github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/libkb/secret_store_mem.go (about)

     1  package libkb
     2  
     3  type SecretStoreMem struct {
     4  	secrets map[NormalizedUsername]LKSecFullSecret
     5  }
     6  
     7  var _ SecretStoreAll = (*SecretStoreMem)(nil)
     8  
     9  func NewSecretStoreMem() *SecretStoreMem {
    10  	return &SecretStoreMem{
    11  		secrets: make(map[NormalizedUsername]LKSecFullSecret),
    12  	}
    13  }
    14  
    15  func (s *SecretStoreMem) RetrieveSecret(m MetaContext, username NormalizedUsername) (LKSecFullSecret, error) {
    16  	secret, ok := s.secrets[username]
    17  	if !ok {
    18  		return LKSecFullSecret{}, NewErrSecretForUserNotFound(username)
    19  	}
    20  	return secret, nil
    21  }
    22  
    23  func (s *SecretStoreMem) StoreSecret(m MetaContext, username NormalizedUsername, secret LKSecFullSecret) error {
    24  	s.secrets[username] = secret
    25  	return nil
    26  }
    27  
    28  func (s *SecretStoreMem) ClearSecret(m MetaContext, username NormalizedUsername) error {
    29  	if username.IsNil() {
    30  		m.Debug("NOOPing SecretStoreMem#ClearSecret for empty username")
    31  		return nil
    32  	}
    33  	delete(s.secrets, username)
    34  	return nil
    35  }
    36  
    37  func (s *SecretStoreMem) GetUsersWithStoredSecrets(m MetaContext) ([]string, error) {
    38  	var usernames []string
    39  	for k := range s.secrets {
    40  		uname := k.String()
    41  		if !isPPSSecretStore(uname) {
    42  			usernames = append(usernames, uname)
    43  		}
    44  	}
    45  	return usernames, nil
    46  }
    47  
    48  func (s *SecretStoreMem) GetOptions(MetaContext) *SecretStoreOptions  { return nil }
    49  func (s *SecretStoreMem) SetOptions(MetaContext, *SecretStoreOptions) {}