Class: CcipherFactory::KCV
- Inherits:
-
Object
- Object
- CcipherFactory::KCV
- Includes:
- SymKeyCipher::SymKeyEncrypt, TR::CondUtils
- Defined in:
- lib/ccipher_factory/kcv/kcv.rb
Defined Under Namespace
Classes: KCVError
Instance Attribute Summary collapse
-
#check_value ⇒ Object
Returns the value of attribute check_value.
-
#nonce ⇒ Object
Returns the value of attribute nonce.
Attributes included from SymKeyCipher::SymKeyEncrypt
Class Method Summary collapse
Instance Method Summary collapse
Methods included from SymKeyCipher::SymKeyEncrypt
#encrypt_final, #encrypt_init, #encrypt_update
Methods included from Compression::CompressionHelper
#compress_data_if_active, #compression_off, #compression_on, #compressor, #decompress_data_if_active, #decompressor, #decompressor_from_encoded, #encode_null_compressor, #is_compression_on?
Methods included from Common
#attach_mode, #cleanup_intOutputBuf, #cleanup_intOutputFile, #detach_mode, #disposeOutput, #intOutputBuf, #intOutputFile, #is_attach_mode?, #is_output_given?, #output, #output_obj, #sanitize_symbol, #write_to_output
Instance Attribute Details
#check_value ⇒ Object
Returns the value of attribute check_value.
12 13 14 |
# File 'lib/ccipher_factory/kcv/kcv.rb', line 12 def check_value @check_value end |
#nonce ⇒ Object
Returns the value of attribute nonce.
12 13 14 |
# File 'lib/ccipher_factory/kcv/kcv.rb', line 12 def nonce @nonce end |
Class Method Details
.converter ⇒ Object
27 28 29 30 31 32 |
# File 'lib/ccipher_factory/kcv/kcv.rb', line 27 def self.converter if @conv.nil? @conv = Ccrypto::UtilFactory.instance(:data_converter) end @conv end |
.from_encoded(bin) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ccipher_factory/kcv/kcv.rb', line 14 def self.from_encoded(bin) ts = BinStruct.instance.struct_from_bin(bin) kcv = KCV.new kcv.mode = BTag.constant_value(ts.mode) kcv.iv = ts.iv kcv.nonce = ts.nonce kcv.check_value = ts.check_value kcv end |
.logger ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/ccipher_factory/kcv/kcv.rb', line 77 def self.logger if @logger.nil? @logger = Tlogger.new @logger.tag = :kcv end @logger end |
Instance Method Details
#encoded(&block) ⇒ Object
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 |
# File 'lib/ccipher_factory/kcv/kcv.rb', line 42 def encoded(&block) raise KCVError, "Key must be given" if is_empty?(@key) logger.debug "Generating KCV" compression_off output(intOutputBuf) if block logger.debug "Block given" @iv = block.call(:kcv_cipher_iv) end encrypt_init(@key) if is_empty?(@nonce) logger.debug "Random nounce" @nonce = SecureRandom.random_bytes(@key.keysize) else logger.debug "Nounce is given" end encrypt_update(@nonce) encrypt_final ts = BinStruct.instance.struct(:kcv) ts.mode = BTag.constant_value(@mode) ts.iv = @iv ts.nonce = @nonce ts.check_value = intOutputBuf.bytes ts.encoded end |
#is_matched? ⇒ Boolean
34 35 36 37 38 39 40 |
# File 'lib/ccipher_factory/kcv/kcv.rb', line 34 def is_matched? logger.tdebug :kcv_match, "Check if KCV matched" encoded res = intOutputBuf.bytes comp = Ccrypto::UtilFactory.instance(:comparator) comp.is_equal?(@check_value, res) end |
#logger ⇒ Object
84 85 86 |
# File 'lib/ccipher_factory/kcv/kcv.rb', line 84 def logger self.class.logger end |