git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/jst/keys_memory.go (about)

     1  package jst
     2  
     3  type KeyProviderMemory struct {
     4  	keys map[string][]byte
     5  }
     6  
     7  func NewKeyProviderMemory(keys map[string][]byte) *KeyProviderMemory {
     8  	return &KeyProviderMemory{
     9  		keys: keys,
    10  	}
    11  }
    12  
    13  func (provider *KeyProviderMemory) GetKey(keyId string) (key []byte, err error) {
    14  	key, exists := provider.keys[keyId]
    15  	if !exists {
    16  		err = ErrKeyNotFound(keyId)
    17  		return
    18  	}
    19  
    20  	return
    21  }