Documentation
¶
Overview ¶
Package inmem provides in-memory implementations of the storage interfaces in the stores package. They are a pure-Go port of rust/protocol/src/storage/inmem.rs and are intended primarily for tests and as the reference behavior other implementations must match.
The stores are not safe for concurrent use; callers needing concurrency must serialize access. Serialized record bytes are defensively copied on save and on read, so a caller can reuse or mutate the buffers it passes in or gets back without disturbing stored state.
Index ¶
- Variables
- type IdentityKeyStore
- func (s *IdentityKeyStore) GetIdentity(_ context.Context, addr address.ProtocolAddress) (curve.PublicKey, bool, error)
- func (s *IdentityKeyStore) GetIdentityKeyPair(_ context.Context) (curve.KeyPair, error)
- func (s *IdentityKeyStore) GetLocalRegistrationID(_ context.Context) (uint32, error)
- func (s *IdentityKeyStore) IsTrustedIdentity(_ context.Context, addr address.ProtocolAddress, identity curve.PublicKey, ...) (bool, error)
- func (s *IdentityKeyStore) Reset()
- func (s *IdentityKeyStore) SaveIdentity(_ context.Context, addr address.ProtocolAddress, identity curve.PublicKey) (stores.IdentityChange, error)
- type KyberPreKeyStore
- func (s *KyberPreKeyStore) AllKyberPreKeyIDs() []uint32
- func (s *KyberPreKeyStore) GetKyberPreKey(_ context.Context, id uint32) ([]byte, error)
- func (s *KyberPreKeyStore) MarkKyberPreKeyUsed(_ context.Context, kyberPreKeyID uint32, ecPreKeyID uint32, ...) error
- func (s *KyberPreKeyStore) SaveKyberPreKey(_ context.Context, id uint32, record []byte) error
- type PreKeyStore
- type SenderKeyStore
- type SessionStore
- type SignedPreKeyStore
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidPreKeyID is returned by GetPreKey for an unknown id. ErrInvalidPreKeyID = errors.New("inmem: invalid pre-key id") // ErrInvalidSignedPreKeyID is returned by GetSignedPreKey for an unknown id. ErrInvalidSignedPreKeyID = errors.New("inmem: invalid signed pre-key id") // ErrInvalidKyberPreKeyID is returned by GetKyberPreKey for an unknown id. ErrInvalidKyberPreKeyID = errors.New("inmem: invalid kyber pre-key id") // ErrReusedBaseKey is returned by MarkKyberPreKeyUsed when the same base key // was already seen for a (kyber, ec) pre-key pair — a replayed pre-key // message. ErrReusedBaseKey = errors.New("inmem: reused base key for kyber pre-key") )
Errors returned when a record is not present, mirroring upstream's InvalidPreKeyId / InvalidSignedPreKeyId / InvalidKyberPreKeyId. They are sentinels matchable with errors.Is.
Functions ¶
This section is empty.
Types ¶
type IdentityKeyStore ¶
type IdentityKeyStore struct {
// contains filtered or unexported fields
}
IdentityKeyStore is the in-memory stores.IdentityKeyStore.
func NewIdentityKeyStore ¶
func NewIdentityKeyStore(keyPair curve.KeyPair, registrationID uint32) *IdentityKeyStore
NewIdentityKeyStore creates an identity store for the given local identity key pair and registration id, with no known remote identities.
func (*IdentityKeyStore) GetIdentity ¶
func (s *IdentityKeyStore) GetIdentity(_ context.Context, addr address.ProtocolAddress) (curve.PublicKey, bool, error)
GetIdentity returns the recorded identity for address and true, or the zero value and false when none is recorded.
func (*IdentityKeyStore) GetIdentityKeyPair ¶
GetIdentityKeyPair returns the local identity key pair.
func (*IdentityKeyStore) GetLocalRegistrationID ¶
func (s *IdentityKeyStore) GetLocalRegistrationID(_ context.Context) (uint32, error)
GetLocalRegistrationID returns the local registration id.
func (*IdentityKeyStore) IsTrustedIdentity ¶
func (s *IdentityKeyStore) IsTrustedIdentity(_ context.Context, addr address.ProtocolAddress, identity curve.PublicKey, _ stores.Direction) (bool, error)
IsTrustedIdentity reports whether identity is trusted for address. Unknown address is trusted (first use); a known address is trusted only if its recorded identity equals identity. Direction does not affect the decision in this reference store.
func (*IdentityKeyStore) Reset ¶
func (s *IdentityKeyStore) Reset()
Reset clears all known remote identities.
func (*IdentityKeyStore) SaveIdentity ¶
func (s *IdentityKeyStore) SaveIdentity(_ context.Context, addr address.ProtocolAddress, identity curve.PublicKey) (stores.IdentityChange, error)
SaveIdentity records identity for address and reports whether it replaced a different existing identity. Unknown address -> NewOrUnchanged (and stored); same identity -> NewOrUnchanged; different identity -> ReplacedExisting (and overwritten).
type KyberPreKeyStore ¶
type KyberPreKeyStore struct {
// contains filtered or unexported fields
}
KyberPreKeyStore is the in-memory stores.KyberPreKeyStore. Like upstream's reference store it never clears keys on use (correct for last-resort keys), and it tracks the base keys seen per (kyber, ec) pre-key pair to reject reuse.
func NewKyberPreKeyStore ¶
func NewKyberPreKeyStore() *KyberPreKeyStore
NewKyberPreKeyStore creates an empty Kyber pre-key store.
func (*KyberPreKeyStore) AllKyberPreKeyIDs ¶
func (s *KyberPreKeyStore) AllKyberPreKeyIDs() []uint32
AllKyberPreKeyIDs returns the ids of all stored Kyber pre-keys, in unspecified order.
func (*KyberPreKeyStore) GetKyberPreKey ¶
GetKyberPreKey returns the serialized record for id, or ErrInvalidKyberPreKeyID.
func (*KyberPreKeyStore) MarkKyberPreKeyUsed ¶
func (s *KyberPreKeyStore) MarkKyberPreKeyUsed(_ context.Context, kyberPreKeyID uint32, ecPreKeyID uint32, baseKey curve.PublicKey) error
MarkKyberPreKeyUsed records the (kyberPreKeyID, ecPreKeyID, baseKey) combination, returning ErrReusedBaseKey if that base key was already seen for the (kyber, ec) pair.
func (*KyberPreKeyStore) SaveKyberPreKey ¶
SaveKyberPreKey stores record under id, overwriting any existing entry.
type PreKeyStore ¶
type PreKeyStore struct {
// contains filtered or unexported fields
}
PreKeyStore is the in-memory stores.PreKeyStore.
func NewPreKeyStore ¶
func NewPreKeyStore() *PreKeyStore
NewPreKeyStore creates an empty pre-key store.
func (*PreKeyStore) AllPreKeyIDs ¶
func (s *PreKeyStore) AllPreKeyIDs() []uint32
AllPreKeyIDs returns the ids of all stored pre-keys, in unspecified order.
func (*PreKeyStore) GetPreKey ¶
GetPreKey returns the serialized record for id, or ErrInvalidPreKeyID.
func (*PreKeyStore) RemovePreKey ¶
func (s *PreKeyStore) RemovePreKey(_ context.Context, id uint32) error
RemovePreKey deletes the entry for id; removing a missing id is a no-op.
func (*PreKeyStore) SavePreKey ¶
SavePreKey stores record under id, overwriting any existing entry.
type SenderKeyStore ¶
type SenderKeyStore struct {
// contains filtered or unexported fields
}
SenderKeyStore is the in-memory stores.SenderKeyStore, keyed by the (sender, distributionID) pair. Records are opaque serialized bytes, defensively copied on store and load.
func NewSenderKeyStore ¶
func NewSenderKeyStore() *SenderKeyStore
NewSenderKeyStore creates an empty sender-key store.
func (*SenderKeyStore) LoadSenderKey ¶
func (s *SenderKeyStore) LoadSenderKey(_ context.Context, sender address.ProtocolAddress, distributionID [16]byte) ([]byte, error)
LoadSenderKey returns the serialized record for (sender, distributionID), or (nil, nil) when none is stored.
func (*SenderKeyStore) StoreSenderKey ¶
func (s *SenderKeyStore) StoreSenderKey(_ context.Context, sender address.ProtocolAddress, distributionID [16]byte, record []byte) error
StoreSenderKey stores record for (sender, distributionID), overwriting any existing entry. A nil record is rejected (mirroring StoreSession): storing nil would be indistinguishable from the (nil, nil) "absent" result LoadSenderKey returns for an unstored key.
type SessionStore ¶
type SessionStore struct {
// contains filtered or unexported fields
}
SessionStore is the in-memory session.Store (the session store interface lives in the session package, not stores/, to avoid a session<->stores import cycle). Records are stored by value: store and load each round-trip the record through its serialized form, so the store never shares a *SessionRecord with a caller and a caller cannot mutate stored state.
func NewSessionStore ¶
func NewSessionStore() *SessionStore
NewSessionStore creates an empty session store.
func (*SessionStore) LoadSession ¶
func (s *SessionStore) LoadSession(_ context.Context, addr address.ProtocolAddress) (*session.SessionRecord, error)
LoadSession returns a fresh copy of the session record for addr, or (nil, nil) when none is stored.
func (*SessionStore) StoreSession ¶
func (s *SessionStore) StoreSession(_ context.Context, addr address.ProtocolAddress, record *session.SessionRecord) error
StoreSession stores a copy of record for addr, overwriting any existing entry. The record is serialized on the way in, so later mutation of the caller's record does not affect stored state.
type SignedPreKeyStore ¶
type SignedPreKeyStore struct {
// contains filtered or unexported fields
}
SignedPreKeyStore is the in-memory stores.SignedPreKeyStore.
func NewSignedPreKeyStore ¶
func NewSignedPreKeyStore() *SignedPreKeyStore
NewSignedPreKeyStore creates an empty signed pre-key store.
func (*SignedPreKeyStore) AllSignedPreKeyIDs ¶
func (s *SignedPreKeyStore) AllSignedPreKeyIDs() []uint32
AllSignedPreKeyIDs returns the ids of all stored signed pre-keys, in unspecified order.
func (*SignedPreKeyStore) GetSignedPreKey ¶
GetSignedPreKey returns the serialized record for id, or ErrInvalidSignedPreKeyID.
func (*SignedPreKeyStore) SaveSignedPreKey ¶
SaveSignedPreKey stores record under id, overwriting any existing entry.