Class: RubyEventStore::Mappers::InMemoryEncryptionKeyRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_event_store/mappers/in_memory_encryption_key_repository.rb

Constant Summary collapse

DEFAULT_CIPHER =
"aes-256-gcm".freeze

Instance Method Summary collapse

Constructor Details

#initializeInMemoryEncryptionKeyRepository

Returns a new instance of InMemoryEncryptionKeyRepository.



8
9
10
# File 'lib/ruby_event_store/mappers/in_memory_encryption_key_repository.rb', line 8

def initialize
  @keys = {}
end

Instance Method Details

#create(identifier, cipher: DEFAULT_CIPHER) ⇒ Object



16
17
18
19
# File 'lib/ruby_event_store/mappers/in_memory_encryption_key_repository.rb', line 16

def create(identifier, cipher: DEFAULT_CIPHER)
  crypto = prepare_encrypt(cipher)
  @keys[[identifier, cipher]] = EncryptionKey.new(cipher: cipher, key: crypto.random_key)
end

#forget(identifier) ⇒ Object



21
22
23
# File 'lib/ruby_event_store/mappers/in_memory_encryption_key_repository.rb', line 21

def forget(identifier)
  @keys = @keys.reject { |(id, _)| id.eql?(identifier) }
end

#key_of(identifier, cipher: DEFAULT_CIPHER) ⇒ Object



12
13
14
# File 'lib/ruby_event_store/mappers/in_memory_encryption_key_repository.rb', line 12

def key_of(identifier, cipher: DEFAULT_CIPHER)
  @keys[[identifier, cipher]]
end