Class: Hiera::Backend::Eyaml::Parser::EncToken
- Defined in:
- lib/hiera/backend/eyaml/parser/encrypted_tokens.rb
Instance Attribute Summary collapse
-
#cipher ⇒ Object
readonly
Returns the value of attribute cipher.
-
#encryptor ⇒ Object
readonly
Returns the value of attribute encryptor.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#indentation ⇒ Object
readonly
Returns the value of attribute indentation.
-
#plain_text ⇒ Object
readonly
Returns the value of attribute plain_text.
Attributes inherited from Token
Class Method Summary collapse
- .decrypted_value(format, plain_text, encryption_scheme, match, id, indentation = '') ⇒ Object
- .encrypted_value(format, encryption_scheme, cipher, match, indentation = '') ⇒ Object
Instance Method Summary collapse
-
#initialize(format, plain_text, encryptor, cipher, match = '', indentation = '', id = nil) ⇒ EncToken
constructor
A new instance of EncToken.
- #to_decrypted(args = {}) ⇒ Object
- #to_encrypted(args = {}) ⇒ Object
- #to_plain_text ⇒ Object
Methods inherited from Token
Constructor Details
#initialize(format, plain_text, encryptor, cipher, match = '', indentation = '', id = nil) ⇒ EncToken
Returns a new instance of EncToken.
25 26 27 28 29 30 31 32 33 |
# File 'lib/hiera/backend/eyaml/parser/encrypted_tokens.rb', line 25 def initialize(format, plain_text, encryptor, cipher, match = '', indentation = '', id = nil) @format = format @plain_text = plain_text @encryptor = encryptor @cipher = cipher @indentation = indentation @id = id super(match) end |
Instance Attribute Details
#cipher ⇒ Object (readonly)
Returns the value of attribute cipher.
12 13 14 |
# File 'lib/hiera/backend/eyaml/parser/encrypted_tokens.rb', line 12 def cipher @cipher end |
#encryptor ⇒ Object (readonly)
Returns the value of attribute encryptor.
12 13 14 |
# File 'lib/hiera/backend/eyaml/parser/encrypted_tokens.rb', line 12 def encryptor @encryptor end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
12 13 14 |
# File 'lib/hiera/backend/eyaml/parser/encrypted_tokens.rb', line 12 def format @format end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/hiera/backend/eyaml/parser/encrypted_tokens.rb', line 12 def id @id end |
#indentation ⇒ Object (readonly)
Returns the value of attribute indentation.
12 13 14 |
# File 'lib/hiera/backend/eyaml/parser/encrypted_tokens.rb', line 12 def indentation @indentation end |
#plain_text ⇒ Object (readonly)
Returns the value of attribute plain_text.
12 13 14 |
# File 'lib/hiera/backend/eyaml/parser/encrypted_tokens.rb', line 12 def plain_text @plain_text end |
Class Method Details
.decrypted_value(format, plain_text, encryption_scheme, match, id, indentation = '') ⇒ Object
18 19 20 21 22 23 |
# File 'lib/hiera/backend/eyaml/parser/encrypted_tokens.rb', line 18 def self.decrypted_value(format, plain_text, encryption_scheme, match, id, indentation = '') encryptor = Encryptor.find encryption_scheme cipher = encryptor.encode( encryptor.encrypt plain_text ) id_number = id.nil? ? nil : id.gsub(/\(|\)/, "").to_i EncToken.new(format, plain_text, encryptor, cipher, match, indentation, id_number) end |
.encrypted_value(format, encryption_scheme, cipher, match, indentation = '') ⇒ Object
13 14 15 16 17 |
# File 'lib/hiera/backend/eyaml/parser/encrypted_tokens.rb', line 13 def self.encrypted_value(format, encryption_scheme, cipher, match, indentation = '') decryptor = Encryptor.find encryption_scheme plain_text = decryptor.decrypt( decryptor.decode cipher ) EncToken.new(format, plain_text, decryptor, cipher, match, indentation) end |
Instance Method Details
#to_decrypted(args = {}) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/hiera/backend/eyaml/parser/encrypted_tokens.rb', line 55 def to_decrypted(args={}) label = args[:label] label_string = label.nil? ? '' : "#{label}: " format = args[:format].nil? ? @format : args[:format] index = args[:index].nil? ? '' : "(#{args[:index]})" case format when :block chevron = (args[:use_chevron].nil? || args[:use_chevron]) ? ">\n" : '' "#{label_string}#{chevron}" + indentation + "DEC#{index}::#{@encryptor.tag}[" + @plain_text + "]!" when :string "#{label_string}DEC#{index}::#{@encryptor.tag}[" + @plain_text + "]!" else raise "#{@format} is not a valid format" end end |
#to_encrypted(args = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/hiera/backend/eyaml/parser/encrypted_tokens.rb', line 35 def to_encrypted(args={}) label = args[:label] label_string = label.nil? ? '' : "#{label}: " format = args[:format].nil? ? @format : args[:format] case format when :block # strip any white space @cipher = @cipher.gsub(/ /m, "") # normalize indentation ciphertext = @cipher.gsub(/\n/, "\n" + @indentation) chevron = (args[:use_chevron].nil? || args[:use_chevron]) ? ">\n" : '' "#{label_string}#{chevron}" + @indentation + "ENC[#{@encryptor.tag},#{ciphertext}]" when :string ciphertext = @cipher.gsub(/\n/, "") "#{label_string}ENC[#{@encryptor.tag},#{ciphertext}]" else raise "#{@format} is not a valid format" end end |
#to_plain_text ⇒ Object
71 72 73 |
# File 'lib/hiera/backend/eyaml/parser/encrypted_tokens.rb', line 71 def to_plain_text @plain_text end |