Class: Ccrypto::CipherConfig
- Inherits:
-
Object
- Object
- Ccrypto::CipherConfig
show all
- Includes:
- AlgoConfig, TR::CondUtils
- Defined in:
- lib/ccrypto/configs/cipher_config.rb
Instance Attribute Summary collapse
Attributes included from AlgoConfig
#provider_config
Instance Method Summary
collapse
Methods included from AlgoConfig
include, #provider_info
Constructor Details
#initialize(algo, opts = { }, &block) ⇒ CipherConfig
Returns a new instance of CipherConfig.
18
19
20
21
22
23
24
25
26
27
28
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
|
# File 'lib/ccrypto/configs/cipher_config.rb', line 18
def initialize(algo, opts = { }, &block)
@algo = algo
@logger = Tlogger.new
@logger.tag = :cipher_conf
if not_empty?(opts) and opts.is_a?(Hash)
@mode = opts[:mode]
if is_mode?(:gcm)
self.extend CipherGCMMode
@logger.debug "Extending GCM 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]
end
if block
@mode = block.call(:mode)
if is_mode?(:gcm)
self.extend CipherGCMMode
@logger.debug "Extending GCM 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)
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
|
#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
|
#mode ⇒ Object
Returns the value of attribute mode.
14
15
16
|
# File 'lib/ccrypto/configs/cipher_config.rb', line 14
def mode
@mode
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
|
Instance Method Details
#decrypt_cipher_mode ⇒ Object
108
109
110
|
# File 'lib/ccrypto/configs/cipher_config.rb', line 108
def decrypt_cipher_mode
@cipherOps = :decrypt
end
|
#encrypt_cipher_mode ⇒ Object
96
97
98
|
# File 'lib/ccrypto/configs/cipher_config.rb', line 96
def encrypt_cipher_mode
@cipherOps = :encrypt
end
|
#has_iv? ⇒ Boolean
72
73
74
|
# File 'lib/ccrypto/configs/cipher_config.rb', line 72
def has_iv?
not_empty?(@iv)
end
|
#has_key? ⇒ Boolean
76
77
78
|
# File 'lib/ccrypto/configs/cipher_config.rb', line 76
def has_key?
not_empty?(@key)
end
|
#is_algo?(algo) ⇒ Boolean
80
81
82
83
84
85
86
|
# File 'lib/ccrypto/configs/cipher_config.rb', line 80
def is_algo?(algo)
if @algo.nil? or is_empty?(@algo)
false
else
(@algo.to_s.downcase =~ /#{algo}/) != nil
end
end
|
#is_decrypt_cipher_mode? ⇒ Boolean
111
112
113
114
115
116
117
118
|
# File 'lib/ccrypto/configs/cipher_config.rb', line 111
def is_decrypt_cipher_mode?
case @cipherOps
when :decrypt, :dec
true
else
false
end
end
|
#is_encrypt_cipher_mode? ⇒ Boolean
99
100
101
102
103
104
105
106
|
# File 'lib/ccrypto/configs/cipher_config.rb', line 99
def is_encrypt_cipher_mode?
case @cipherOps
when :encrypt, :enc
true
else
false
end
end
|
#is_mode?(mode) ⇒ Boolean
88
89
90
91
92
93
94
|
# File 'lib/ccrypto/configs/cipher_config.rb', line 88
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
124
125
126
127
128
129
130
|
# File 'lib/ccrypto/configs/cipher_config.rb', line 124
def logger
if @logger.nil?
@logger = Tlogger.new
@logger.tag = :cipher_conf
end
@logger
end
|
#to_s ⇒ Object
120
121
122
|
# File 'lib/ccrypto/configs/cipher_config.rb', line 120
def to_s
"#{@algo}-#{@keysize}-#{@mode}-#{@padding}"
end
|