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 (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) WriteWithNoSecrets(w Writer) error
- type JSONReader
- type JSONWriter
- type Manager
- 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 ReadWithNoSecrets ¶
ReadWithNoSecrets tries to create a keyset.Handle from a keyset obtained via reader.
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) 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 binary proto 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.
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).