Class: Ccrypto::CipherConfig
- Inherits:
-
Object
- Object
- Ccrypto::CipherConfig
- Includes:
- AlgoConfig, TR::CondUtils
- Defined in:
- lib/ccrypto/configs/cipher_config.rb
Instance Attribute Summary collapse
-
#algo ⇒ Object
Returns the value of attribute algo.
-
#cipherOps ⇒ Object
Returns the value of attribute cipherOps.
-
#ciphertext_length ⇒ Object
required by certain mode such as CCM.
-
#iv ⇒ Object
Returns the value of attribute iv.
-
#ivLength ⇒ Object
Returns the value of attribute ivLength.
-
#key ⇒ Object
Returns the value of attribute key.
-
#keysize ⇒ Object
Returns the value of attribute keysize.
-
#mandatory_block_size ⇒ Object
readonly
Use cases : openssl aes-128-xts only accepts input min 16 bytes other no padding mode aes128-wrap only works on block of 8 bytes.
-
#min_input_length ⇒ Object
readonly
Use cases : openssl aes-128-xts only accepts input min 16 bytes other no padding mode aes128-wrap only works on block of 8 bytes.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#native_config ⇒ Object
provider specific.
-
#padding ⇒ Object
Returns the value of attribute padding.
-
#plaintext_length ⇒ Object
required by certain mode such as CCM.
Attributes included from AlgoConfig
Instance Method Summary collapse
- #decrypt_cipher_mode ⇒ Object
- #encrypt_cipher_mode ⇒ Object
- #has_iv? ⇒ Boolean
- #has_key? ⇒ Boolean
-
#initialize(algo, opts = { }, &block) ⇒ CipherConfig
constructor
A new instance of CipherConfig.
- #is_algo?(algo) ⇒ Boolean
- #is_auth_mode_cipher? ⇒ Boolean
- #is_decrypt_cipher_mode? ⇒ Boolean
- #is_encrypt_cipher_mode? ⇒ Boolean
- #is_mode?(mode) ⇒ Boolean
- #logger ⇒ Object
- #to_s ⇒ Object
Methods included from AlgoConfig
Constructor Details
#initialize(algo, opts = { }, &block) ⇒ CipherConfig
Returns a new instance of CipherConfig.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/ccrypto/configs/cipher_config.rb', line 29 def initialize(algo, opts = { }, &block) @algo = algo @logger = Tlogger.new @logger.tag = :cipher_conf @authMode = false @plaintext_length = 0 @ciphertext_length = 0 @min_input_length = -1 @mandatory_Block_size = -1 if not_empty?(opts) and opts.is_a?(Hash) @mode = opts[:mode] @authMode = opts[:authMode] || false #if is_mode?(:gcm) if @authMode self.extend CipherAuthMode @logger.debug "Extending auth mode" @auth_data = opts[:auth_data] @auth_tag = opts[:auth_tag] end @iv = opts[:iv] @ivLength = opts[:ivLength] if is_empty?(@iv) @key = opts[:key] @keysize = opts[:keysize] if is_empty?(@key) @padding = opts[:padding] @cipherOps = opts[:cipherOps] @min_input_length = opts[:min_input_length] || -1 @mandatory_block_size = opts[:mandatory_block_size] || -1 end #if block # @mode = block.call(:mode) # #if is_mode?(:gcm) # if @authMode # self.extend CipherAuthMode # @logger.debug "Extending auth mode" # @auth_data = block.call(:auth_data) # @auth_tag = block.call(:auth_tag) # end # @iv = block.call(:iv) # @ivLength = block.call(:ivLength) || 16 if @iv.nil? # @key = block.call(:key) # @keysize = block.call(:keysize) if @key.nil? # @padding = block.call(:padding) # @cipherOps = block.call(:cipherOps) # @plaintext_length = 0 # @ciphertext_length = 0 # @min_input_length = opts[:min_input_length] || -1 #end end |
Instance Attribute Details
#algo ⇒ Object
Returns the value of attribute algo.
13 14 15 |
# File 'lib/ccrypto/configs/cipher_config.rb', line 13 def algo @algo end |
#cipherOps ⇒ Object
Returns the value of attribute cipherOps.
16 17 18 |
# File 'lib/ccrypto/configs/cipher_config.rb', line 16 def cipherOps @cipherOps end |
#ciphertext_length ⇒ Object
required by certain mode such as CCM
19 20 21 |
# File 'lib/ccrypto/configs/cipher_config.rb', line 19 def ciphertext_length @ciphertext_length end |
#iv ⇒ Object
Returns the value of attribute iv.
15 16 17 |
# File 'lib/ccrypto/configs/cipher_config.rb', line 15 def iv @iv end |
#ivLength ⇒ Object
Returns the value of attribute ivLength.
15 16 17 |
# File 'lib/ccrypto/configs/cipher_config.rb', line 15 def ivLength @ivLength end |
#key ⇒ Object
Returns the value of attribute key.
13 14 15 |
# File 'lib/ccrypto/configs/cipher_config.rb', line 13 def key @key end |
#keysize ⇒ Object
Returns the value of attribute keysize.
14 15 16 |
# File 'lib/ccrypto/configs/cipher_config.rb', line 14 def keysize @keysize end |
#mandatory_block_size ⇒ Object (readonly)
Use cases : openssl aes-128-xts only accepts input min 16 bytes other no padding mode aes128-wrap only works on block of 8 bytes
24 25 26 |
# File 'lib/ccrypto/configs/cipher_config.rb', line 24 def mandatory_block_size @mandatory_block_size end |
#min_input_length ⇒ Object (readonly)
Use cases : openssl aes-128-xts only accepts input min 16 bytes other no padding mode aes128-wrap only works on block of 8 bytes
24 25 26 |
# File 'lib/ccrypto/configs/cipher_config.rb', line 24 def min_input_length @min_input_length end |
#mode ⇒ Object
Returns the value of attribute mode.
14 15 16 |
# File 'lib/ccrypto/configs/cipher_config.rb', line 14 def mode @mode end |
#native_config ⇒ Object
provider specific
27 28 29 |
# File 'lib/ccrypto/configs/cipher_config.rb', line 27 def native_config @native_config end |
#padding ⇒ Object
Returns the value of attribute padding.
14 15 16 |
# File 'lib/ccrypto/configs/cipher_config.rb', line 14 def padding @padding end |
#plaintext_length ⇒ Object
required by certain mode such as CCM
19 20 21 |
# File 'lib/ccrypto/configs/cipher_config.rb', line 19 def plaintext_length @plaintext_length end |
Instance Method Details
#decrypt_cipher_mode ⇒ Object
142 143 144 |
# File 'lib/ccrypto/configs/cipher_config.rb', line 142 def decrypt_cipher_mode @cipherOps = :decrypt end |
#encrypt_cipher_mode ⇒ Object
130 131 132 |
# File 'lib/ccrypto/configs/cipher_config.rb', line 130 def encrypt_cipher_mode @cipherOps = :encrypt end |
#has_iv? ⇒ Boolean
102 103 104 |
# File 'lib/ccrypto/configs/cipher_config.rb', line 102 def has_iv? not_empty?(@iv) end |
#has_key? ⇒ Boolean
106 107 108 |
# File 'lib/ccrypto/configs/cipher_config.rb', line 106 def has_key? not_empty?(@key) end |
#is_algo?(algo) ⇒ Boolean
114 115 116 117 118 119 120 |
# File 'lib/ccrypto/configs/cipher_config.rb', line 114 def is_algo?(algo) if @algo.nil? or is_empty?(@algo) false else (@algo.to_s.downcase =~ /#{algo}/) != nil end end |
#is_auth_mode_cipher? ⇒ Boolean
110 111 112 |
# File 'lib/ccrypto/configs/cipher_config.rb', line 110 def is_auth_mode_cipher? @authMode end |
#is_decrypt_cipher_mode? ⇒ Boolean
145 146 147 148 149 150 151 152 |
# File 'lib/ccrypto/configs/cipher_config.rb', line 145 def is_decrypt_cipher_mode? case @cipherOps when :decrypt, :dec true else false end end |
#is_encrypt_cipher_mode? ⇒ Boolean
133 134 135 136 137 138 139 140 |
# File 'lib/ccrypto/configs/cipher_config.rb', line 133 def is_encrypt_cipher_mode? case @cipherOps when :encrypt, :enc true else false end end |
#is_mode?(mode) ⇒ Boolean
122 123 124 125 126 127 128 |
# File 'lib/ccrypto/configs/cipher_config.rb', line 122 def is_mode?(mode) if @mode.nil? or is_empty?(@mode) false else (@mode.to_s.downcase =~ /#{mode.to_s}/) != nil end end |
#logger ⇒ Object
160 161 162 163 164 165 166 |
# File 'lib/ccrypto/configs/cipher_config.rb', line 160 def logger if @logger.nil? @logger = Tlogger.new @logger.tag = :cipher_conf end @logger end |
#to_s ⇒ Object
154 155 156 157 158 |
# File 'lib/ccrypto/configs/cipher_config.rb', line 154 def to_s res = [@algo, @keysize, @mode, @padding].reject { |v| is_empty?(v) }.join("-") "#{res} (#{@authMode})" #"#{@algo}-#{@keysize}-#{@mode}-#{@padding}" end |