lib/ccrypto/configs/cipher_config.rb in ccrypto-0.1.2 vs lib/ccrypto/configs/cipher_config.rb in ccrypto-0.1.3
- old
+ new
@@ -14,11 +14,11 @@
attr_accessor :keysize, :mode, :padding
attr_accessor :iv, :ivLength
attr_accessor :cipherOps
# required by certain mode such as CCM
- attr_accessor :plaintext_length, :ciphertext_length
+ attr_accessor :plaintext_length, :ciphertext_length, :fixed_auth_tag_length
# 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
attr_reader :min_input_length, :mandatory_block_size
@@ -35,10 +35,11 @@
@authMode = false
@plaintext_length = 0
@ciphertext_length = 0
@min_input_length = -1
@mandatory_Block_size = -1
+ @fixed_iv_length = -1
if not_empty?(opts) and opts.is_a?(Hash)
@mode = opts[:mode]
@authMode = opts[:authMode] || false
@@ -64,10 +65,12 @@
@min_input_length = opts[:min_input_length] || -1
@mandatory_block_size = opts[:mandatory_block_size] || -1
+ @fixed_auth_tag_length = opts[:fixed_auth_tag_length] || -1
+
end
#if block
# @mode = block.call(:mode)
@@ -105,12 +108,20 @@
def has_key?
not_empty?(@key)
end
+ def has_min_input_length?
+ not_empty?(@min_input_length) and @min_input_length.to_i > -1
+ end
+
+ def has_fixed_auth_tag_length?
+ not_empty?(@fixed_auth_tag_length) and @fixed_auth_tag_length.to_i > -1
+ end
+
def is_auth_mode_cipher?
- @authMode
+ @authMode == true
end
def is_algo?(algo)
if @algo.nil? or is_empty?(@algo)
false
@@ -121,11 +132,19 @@
def is_mode?(mode)
if @mode.nil? or is_empty?(@mode)
false
else
- (@mode.to_s.downcase =~ /#{mode.to_s}/) != nil
+ (@mode.to_s.downcase =~ /#{mode.to_s.downcase}/) != nil
end
+ end
+
+ def needs_plaintext_length?
+ is_mode?(:ccm)
+ end
+
+ def needs_ciphertext_length?
+ is_mode?(:ccm)
end
def encrypt_cipher_mode
@cipherOps = :encrypt
end