func()

in linux/tpm.go [278:310]


func (tpm *tpmDevice) LoadKey(keyID string, parentHandle, persistentHandle tpmutil.Handle, template *tpm2.Public) (CryptoKey, error) {
	cpKey, err := tpm.LoadDiskKey(keyID)
	if err != nil {
		return nil, err
	}

	if cpKey == nil || cpKey.IsEmpty() {
		flog.Warningf("Key '%s' not found, attempting to create it", keyID)

		cpKey, err = tpm.GenerateKey(
			parentHandle, keyID, persistentHandle, template)
		if err != nil {
			return nil, err
		}
		if cpKey == nil || cpKey.IsEmpty() {
			return nil, errors.New("failed to load key: empty key found")
		}
	}

	loadedHandle, _, err := tpm2.Load(
		tpm.rwc,
		parentHandle,
		"",
		cpKey.GetPublicBytes(),
		cpKey.GetPrivateBytes(),
	)
	if err != nil {
		return nil, err
	}

	cpKey.SetLoadedHandle(loadedHandle)
	return cpKey, nil
}