Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions p11/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type Session interface {
GenerateKeyPair(request GenerateKeyPairRequest) (*KeyPair, error)
// GenerateRandom returns random bytes generated by the token.
GenerateRandom(length int) ([]byte, error)
// Wrap key returns ciphertext bytes from wrapping a key with another key
WrapKey(request WrapKeyRequest) ([]byte, error)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This session interface starts looking like a dumping ground for methods, can you find a better way than adding another method here?


// InitPIN initialize's the normal user's PIN.
InitPIN(pin string) error
Expand Down Expand Up @@ -191,3 +193,20 @@ func (s *sessionImpl) GenerateKeyPair(request GenerateKeyPairRequest) (*KeyPair,
}),
}, nil
}

// WrapKeyRequest contains the fields used to wrap a key.
type WrapKeyRequest struct {
Mechanism pkcs11.Mechanism
WrappingObject Object
Object Object
}

func (s *sessionImpl) WrapKey(request WrapKeyRequest) ([]byte, error) {
s.Lock()
defer s.Unlock()
return s.ctx.WrapKey(s.handle,
[]*pkcs11.Mechanism{&request.Mechanism},
request.WrappingObject.objectHandle,
request.Object.objectHandle)

}