Module: CcipherFactory::Common
- Includes:
- TR::CondUtils
- Included in:
- AsymKeyCipher::ECCAttDecrypt, AsymKeyCipher::ECCAttEncrypt, AsymKeyCipher::ECCDecrypt, AsymKeyCipher::ECCEncrypt, AsymKeySigner::ECCAttSigner, AsymKeySigner::ECCAttVerifier, AsymKeySigner::ECCSigner, AsymKeySigner::ECCVerifier, CcipherFactory::CompositeCipher::DecryptVerifier, CcipherFactory::CompositeCipher::SignEncryptor, CcipherFactory::Compression::ZlibCompressor, CcipherFactory::Compression::ZlibDecompressor, DerivedSymKey, Digest, KDF::HKDF, KDF::PBKDF2, KDF::Scrypt, SoftSymKey, SymKeyCipher::SymKeyAttDecrypt, SymKeyCipher::SymKeyAttEncrypt, SymKeyCipher::SymKeyDecrypt, SymKeyCipher::SymKeyEncrypt, SymKeySigner::SymKeyAttSign, SymKeySigner::SymKeyAttVerify, SymKeySigner::SymKeySign
- Defined in:
- lib/ccipher_factory/helpers/common.rb
Instance Method Summary collapse
-
#attach_mode ⇒ Object
attached mode Flag to indicate if the result of the operation should be part of the header/meta data directly return from the API.
- #cleanup_intOutputBuf ⇒ Object
- #cleanup_intOutputFile ⇒ Object
- #detach_mode ⇒ Object
- #disposeOutput(obj) ⇒ Object
- #intOutputBuf ⇒ Object
- #intOutputFile ⇒ Object
- #is_attach_mode? ⇒ Boolean
- #is_output_given? ⇒ Boolean
-
#output(output) ⇒ Object
output section.
- #output_obj ⇒ Object
- #sanitize_symbol(sym, conv = :downcase) ⇒ Object
- #write_to_output(val) ⇒ Object
Instance Method Details
#attach_mode ⇒ Object
attached mode Flag to indicate if the result of the operation should be part of the header/meta data directly return from the API
82 83 84 |
# File 'lib/ccipher_factory/helpers/common.rb', line 82 def attach_mode @attachMode = true end |
#cleanup_intOutputBuf ⇒ Object
35 36 37 38 39 |
# File 'lib/ccipher_factory/helpers/common.rb', line 35 def cleanup_intOutputBuf if not @intOutputBuf.nil? @intOutputBuf = nil end end |
#cleanup_intOutputFile ⇒ Object
48 49 50 51 52 53 |
# File 'lib/ccipher_factory/helpers/common.rb', line 48 def cleanup_intOutputFile if not @intOutputFile.nil? @intOutputFile.close! @intOutputFile = nil end end |
#detach_mode ⇒ Object
86 87 88 |
# File 'lib/ccipher_factory/helpers/common.rb', line 86 def detach_mode @attachMode = false end |
#disposeOutput(obj) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ccipher_factory/helpers/common.rb', line 55 def disposeOutput(obj) case obj when intOutputBuf cnt = 0 len = @intOutputBuf.length loop do @intOutputBuf.rewind @intOutputBuf.write(SecureRandom.random_bytes(len)) cnt += 1 break if cnt >= 16 end @intOutputBuf.rewind @intOutputBuf = nil when intOutputFile @intOutputFile.close! end end |
#intOutputBuf ⇒ Object
28 29 30 31 32 33 |
# File 'lib/ccipher_factory/helpers/common.rb', line 28 def intOutputBuf if @intOutputBuf.nil? @intOutputBuf = MemBuf.new end @intOutputBuf end |
#intOutputFile ⇒ Object
41 42 43 44 45 46 |
# File 'lib/ccipher_factory/helpers/common.rb', line 41 def intOutputFile if @intOutputFile.nil? @intOutputFile = Tempfile.new end @intOutputFile end |
#is_attach_mode? ⇒ Boolean
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/ccipher_factory/helpers/common.rb', line 90 def is_attach_mode? if @attachMode.nil? or not is_bool?(@attachMode) # default detach # The impact is mainly on huge data encrypt/decrypt # Returning the huge data through the API returned might # have undetermined behaviour false else @attachMode end end |
#is_output_given? ⇒ Boolean
24 25 26 |
# File 'lib/ccipher_factory/helpers/common.rb', line 24 def is_output_given? not @output.nil? end |
#output(output) ⇒ Object
output section
11 12 13 14 |
# File 'lib/ccipher_factory/helpers/common.rb', line 11 def output(output) raise CcipherFactory::Error, "Output requires to support write(). StringIO is a good example." if output.nil? or not output.respond_to?(:write) @output = output end |
#output_obj ⇒ Object
16 17 18 |
# File 'lib/ccipher_factory/helpers/common.rb', line 16 def output_obj @output end |
#sanitize_symbol(sym, conv = :downcase) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/ccipher_factory/helpers/common.rb', line 106 def sanitize_symbol(sym, conv = :downcase) if not_empty?(sym) case conv when :downcase sym.to_s.downcase.to_sym when :upcase sym.to_s.upcase.to_sym when :capitalize sym.to_s.capitalize.to_sym else sym end else sym end end |
#write_to_output(val) ⇒ Object
20 21 22 |
# File 'lib/ccipher_factory/helpers/common.rb', line 20 def write_to_output(val) @output.write(val) if not @output.nil? and not_empty?(val) end |