Documentation ¶
Overview ¶
Package keyset provides methods to generate, read, write or validate keysets.
Index ¶
- func Validate(keyset *tinkpb.Keyset) error
- func ValidateKeyVersion(version, maxExpected uint32) error
- type BinaryReader
- type BinaryWriter
- type Handle
- func NewHandle(kt *tinkpb.KeyTemplate) (*Handle, error)
- func NewHandleWithNoSecrets(ks *tinkpb.Keyset) (*Handle, error)
- func Read(reader Reader, masterKey tink.AEAD) (*Handle, error)
- func ReadWithAssociatedData(reader Reader, masterKey tink.AEAD, associatedData []byte) (*Handle, error)
- func ReadWithNoSecrets(reader Reader) (*Handle, error)
- func (h *Handle) KeysetInfo() *tinkpb.KeysetInfo
- func (h *Handle) Primitives() (*primitiveset.PrimitiveSet, error)
- func (h *Handle) PrimitivesWithKeyManager(km registry.KeyManager) (*primitiveset.PrimitiveSet, error)
- func (h *Handle) Public() (*Handle, error)
- func (h *Handle) String() string
- func (h *Handle) Write(writer Writer, masterKey tink.AEAD) error
- func (h *Handle) WriteWithAssociatedData(writer Writer, masterKey tink.AEAD, associatedData []byte) error
- func (h *Handle) WriteWithNoSecrets(w Writer) error
- type JSONReader
- type JSONWriter
- type Manager
- func (km *Manager) Add(kt *tinkpb.KeyTemplate) (uint32, error)
- func (km *Manager) Delete(keyID uint32) error
- func (km *Manager) Disable(keyID uint32) error
- func (km *Manager) Enable(keyID uint32) error
- func (km *Manager) Handle() (*Handle, error)
- func (km *Manager) Rotate(kt *tinkpb.KeyTemplate) errordeprecated
- func (km *Manager) SetPrimary(keyID uint32) error
- type MemReaderWriter
- type Reader
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Validate ¶
Validate validates the given key set. Returns nil if it is valid; an error otherwise.
func ValidateKeyVersion ¶
ValidateKeyVersion checks whether the given version is valid. The version is valid only if it is the range [0..maxExpected]
Types ¶
type BinaryReader ¶
type BinaryReader struct {
// contains filtered or unexported fields
}
BinaryReader deserializes a keyset from binary proto format.
func NewBinaryReader ¶
func NewBinaryReader(r io.Reader) *BinaryReader
NewBinaryReader returns new BinaryReader that will read from r.
func (*BinaryReader) Read ¶
func (bkr *BinaryReader) Read() (*tinkpb.Keyset, error)
Read parses a (cleartext) keyset from the underlying io.Reader.
func (*BinaryReader) ReadEncrypted ¶
func (bkr *BinaryReader) ReadEncrypted() (*tinkpb.EncryptedKeyset, error)
ReadEncrypted parses an EncryptedKeyset from the underlying io.Reader.
type BinaryWriter ¶
type BinaryWriter struct {
// contains filtered or unexported fields
}
BinaryWriter serializes a keyset into binary proto format.
func NewBinaryWriter ¶
func NewBinaryWriter(w io.Writer) *BinaryWriter
NewBinaryWriter returns a new BinaryWriter that will write to w.
func (*BinaryWriter) Write ¶
func (bkw *BinaryWriter) Write(keyset *tinkpb.Keyset) error
Write writes the keyset to the underlying io.Writer.
func (*BinaryWriter) WriteEncrypted ¶
func (bkw *BinaryWriter) WriteEncrypted(keyset *tinkpb.EncryptedKeyset) error
WriteEncrypted writes the encrypted keyset to the underlying io.Writer.
type Handle ¶
type Handle struct {
// contains filtered or unexported fields
}
Handle provides access to a Keyset protobuf, to limit the exposure of actual protocol buffers that hold sensitive key material.
func NewHandle ¶
func NewHandle(kt *tinkpb.KeyTemplate) (*Handle, error)
NewHandle creates a keyset handle that contains a single fresh key generated according to the given KeyTemplate.
func NewHandleWithNoSecrets ¶
NewHandleWithNoSecrets creates a new instance of KeysetHandle using the given keyset which does not contain any secret key material.
func ReadWithAssociatedData ¶ added in v1.7.0
func ReadWithAssociatedData(reader Reader, masterKey tink.AEAD, associatedData []byte) (*Handle, error)
ReadWithAssociatedData tries to create a Handle from an encrypted keyset obtained via reader using the provided associated data.
func ReadWithNoSecrets ¶
ReadWithNoSecrets tries to create a keyset.Handle from a keyset obtained via reader.
func (*Handle) KeysetInfo ¶ added in v1.5.0
func (h *Handle) KeysetInfo() *tinkpb.KeysetInfo
KeysetInfo returns KeysetInfo representation of the managed keyset. The result does not contain any sensitive key material.
func (*Handle) Primitives ¶
func (h *Handle) Primitives() (*primitiveset.PrimitiveSet, error)
Primitives creates a set of primitives corresponding to the keys with status=ENABLED in the keyset of the given keyset handle, assuming all the corresponding key managers are present (keys with status!=ENABLED are skipped).
The returned set is usually later "wrapped" into a class that implements the corresponding Primitive-interface.
func (*Handle) PrimitivesWithKeyManager ¶
func (h *Handle) PrimitivesWithKeyManager(km registry.KeyManager) (*primitiveset.PrimitiveSet, error)
PrimitivesWithKeyManager creates a set of primitives corresponding to the keys with status=ENABLED in the keyset of the given keysetHandle, using the given key manager (instead of registered key managers) for keys supported by it. Keys not supported by the key manager are handled by matching registered key managers (if present), and keys with status!=ENABLED are skipped.
This enables custom treatment of keys, for example providing extra context (e.g. credentials for accessing keys managed by a KMS), or gathering custom monitoring/profiling information.
The returned set is usually later "wrapped" into a class that implements the corresponding Primitive-interface.
func (*Handle) Public ¶
Public returns a Handle of the public keys if the managed keyset contains private keys.
func (*Handle) String ¶
String returns a string representation of the managed keyset. The result does not contain any sensitive key material.
func (*Handle) WriteWithAssociatedData ¶ added in v1.7.0
func (h *Handle) WriteWithAssociatedData(writer Writer, masterKey tink.AEAD, associatedData []byte) error
WriteWithAssociatedData encrypts and writes the enclosing keyset using the provided associated data.
func (*Handle) WriteWithNoSecrets ¶
WriteWithNoSecrets exports the keyset in h to the given Writer w returning an error if the keyset contains secret key material.
type JSONReader ¶
type JSONReader struct {
// contains filtered or unexported fields
}
JSONReader deserializes a keyset from json format.
func NewJSONReader ¶
func NewJSONReader(r io.Reader) *JSONReader
NewJSONReader returns new JSONReader that will read from r.
func (*JSONReader) Read ¶
func (bkr *JSONReader) Read() (*tinkpb.Keyset, error)
Read parses a (cleartext) keyset from the underlying io.Reader.
func (*JSONReader) ReadEncrypted ¶
func (bkr *JSONReader) ReadEncrypted() (*tinkpb.EncryptedKeyset, error)
ReadEncrypted parses an EncryptedKeyset from the underlying io.Reader.
type JSONWriter ¶
type JSONWriter struct {
// contains filtered or unexported fields
}
JSONWriter serializes a keyset into json format.
func NewJSONWriter ¶
func NewJSONWriter(w io.Writer) *JSONWriter
NewJSONWriter returns a new JSONWriter that will write to w.
func (*JSONWriter) Write ¶
func (bkw *JSONWriter) Write(keyset *tinkpb.Keyset) error
Write writes the keyset to the underlying io.Writer.
func (*JSONWriter) WriteEncrypted ¶
func (bkw *JSONWriter) WriteEncrypted(keyset *tinkpb.EncryptedKeyset) error
WriteEncrypted writes the encrypted keyset to the underlying io.Writer.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages a Keyset-proto, with convenience methods that rotate, disable, enable or destroy keys. Note: It is not thread-safe.
func NewManager ¶
func NewManager() *Manager
NewManager creates a new instance with an empty Keyset.
func NewManagerFromHandle ¶
NewManagerFromHandle creates a new instance from the given Handle.
func (*Manager) Add ¶ added in v1.7.0
func (km *Manager) Add(kt *tinkpb.KeyTemplate) (uint32, error)
Add generates and adds a fresh key using the given key template. the key is enabled on creation, but not set to primary. It returns the ID of the new key
func (*Manager) Delete ¶ added in v1.7.0
Delete will delete the key with given keyID, removing the key from the keyset entirely. Returns an error if the key is not found or it is the primary key.
func (*Manager) Disable ¶ added in v1.7.0
Disable will disable the key with given keyID. Returns an error if the key is not found or it is the primary key.
func (*Manager) Enable ¶ added in v1.7.0
Enable will enable the key with given keyID. Returns an error if the key is not found or is not enabled or disabled already.
func (*Manager) Rotate
deprecated
func (km *Manager) Rotate(kt *tinkpb.KeyTemplate) error
Rotate generates a fresh key using the given key template and sets the new key as the primary key.
Deprecated: please use Add instead. Rotate adds a new key and immediately promotes it to primary. However, when performing keyset rotation, you almost never want a newly added key to immediately be set as the primary key. Instead, you want to allow sufficient time for key propagation to occur.
func (*Manager) SetPrimary ¶ added in v1.7.0
SetPrimary sets the key with given keyID as primary. Returns an error if the key is not found or not enabled.
type MemReaderWriter ¶
type MemReaderWriter struct { Keyset *tinkpb.Keyset EncryptedKeyset *tinkpb.EncryptedKeyset }
MemReaderWriter implements keyset.Reader and keyset.Writer for *tinkpb.Keyset and *tinkpb.EncryptedKeyset.
func (*MemReaderWriter) Read ¶
func (m *MemReaderWriter) Read() (*tinkpb.Keyset, error)
Read returns *tinkpb.Keyset from memory.
func (*MemReaderWriter) ReadEncrypted ¶
func (m *MemReaderWriter) ReadEncrypted() (*tinkpb.EncryptedKeyset, error)
ReadEncrypted returns *tinkpb.EncryptedKeyset from memory.
func (*MemReaderWriter) Write ¶
func (m *MemReaderWriter) Write(keyset *tinkpb.Keyset) error
Write keyset to memory.
func (*MemReaderWriter) WriteEncrypted ¶
func (m *MemReaderWriter) WriteEncrypted(keyset *tinkpb.EncryptedKeyset) error
WriteEncrypted keyset to memory.
type Reader ¶
type Reader interface { // Read returns a (cleartext) Keyset object from the underlying source. Read() (*tinkpb.Keyset, error) // ReadEncrypted returns an EncryptedKeyset object from the underlying source. ReadEncrypted() (*tinkpb.EncryptedKeyset, error) }
Reader knows how to read a Keyset or an EncryptedKeyset from some source. In order to turn a Reader into a KeysetHandle for use, callers must use insecure.KeysetHandle or by keyset.Read (with encryption).