Module: Ccrypto::Ruby::PEMStore

Includes:
DataConversion, TR::CondUtils
Included in:
ECCKeyBundle, KSPemStore, RSAKeyBundle
Defined in:
lib/ccrypto/ruby/keybundle_store/pem_store.rb

Defined Under Namespace

Modules: ClassMethods Classes: PEMStoreException

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DataConversion

#from_b64, #from_hex, #to_b64, #to_hex, #to_int_array

Class Method Details

.included(klass) ⇒ Object



48
49
50
# File 'lib/ccrypto/ruby/keybundle_store/pem_store.rb', line 48

def self.included(klass)
  klass.extend(ClassMethods)
end

Instance Method Details

#to_pem(&block) ⇒ Object

Raises:



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/ccrypto/ruby/keybundle_store/pem_store.rb', line 52

def to_pem(&block)
  raise PEMStoreException, "Block is required" if not block
  kcipher = block.call(:store_cipher) 
  kpass = block.call(:store_pass)

  kcipher = "AES-256-GCM" if is_empty?(kcipher)

  keypair = block.call(:keypair)
  raise PEMStoreException, "Keypair is required" if is_empty?(keypair)

  if not_empty?(kpass)
    kCipher = OpenSSL::Cipher.new(kcipher)
    keypair.export(kCipher, kpass)
  else
    keypair.export
  end

end