class Hiera::Backend::Eyaml::Parser::EncToken
Attributes
cipher[R]
encryptor[R]
format[R]
id[R]
indentation[R]
plain_text[R]
Public Class Methods
decrypted_value(format, plain_text, encryption_scheme, match, id, indentation = '')
click to toggle source
# File lib/hiera/backend/eyaml/parser/encrypted_tokens.rb, line 21 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
encrypt_unchanged()
click to toggle source
# File lib/hiera/backend/eyaml/parser/encrypted_tokens.rb, line 41 def self.encrypt_unchanged return @@encrypt_unchanged end
encrypted_value(format, encryption_scheme, cipher, match, indentation = '')
click to toggle source
# File lib/hiera/backend/eyaml/parser/encrypted_tokens.rb, line 16 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
new(format, plain_text, encryptor, cipher, match = '', indentation = '', id = nil)
click to toggle source
Calls superclass method
# File lib/hiera/backend/eyaml/parser/encrypted_tokens.rb, line 45 def initialize(format, plain_text, encryptor, cipher, match = '', indentation = '', id = nil) @format = format @plain_text = Utils.convert_to_utf_8( plain_text ) @encryptor = encryptor @cipher = cipher @indentation = indentation @id = id super(match) end
plain_text_value(format, plain_text, encryption_scheme, match, id, indentation = '')
click to toggle source
# File lib/hiera/backend/eyaml/parser/encrypted_tokens.rb, line 27 def self.plain_text_value(format, plain_text, encryption_scheme, match, id, indentation = '') encryptor = Encryptor.find encryption_scheme id_number = id.gsub(/\(|\)/,"").to_i unless id.nil? EncToken.new(format, plain_text, encryptor, "", match, indentation, id_number) end
set_encrypt_unchanged(encrypt_unchanged)
click to toggle source
# File lib/hiera/backend/eyaml/parser/encrypted_tokens.rb, line 37 def self.set_encrypt_unchanged(encrypt_unchanged) @@encrypt_unchanged = encrypt_unchanged end
tokens_map()
click to toggle source
# File lib/hiera/backend/eyaml/parser/encrypted_tokens.rb, line 33 def self.tokens_map return @@tokens_map end
Public Instance Methods
to_decrypted(args={})
click to toggle source
# File lib/hiera/backend/eyaml/parser/encrypted_tokens.rb, line 80 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]})" if @@encrypt_unchanged == false EncToken.tokens_map[index] = @plain_text end 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={})
click to toggle source
# File lib/hiera/backend/eyaml/parser/encrypted_tokens.rb, line 55 def to_encrypted(args={}) label = args[:label] label_string = label.nil? ? '' : "#{label}: " format = args[:format].nil? ? @format : args[:format] encryption_method = args[:change_encryption] if encryption_method != nil @encryptor = Encryptor.find encryption_method @cipher = Base64.encode64(@encryptor.encrypt @plain_text).strip end case format when :block # strip any white space @cipher = @cipher.gsub(/[ \t]/, "") # normalize indentation ciphertext = @cipher.gsub(/[\n\r]/, "\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\r]/, "") "#{label_string}ENC[#{@encryptor.tag},#{ciphertext}]" else raise "#{@format} is not a valid format" end end
to_plain_text()
click to toggle source
# File lib/hiera/backend/eyaml/parser/encrypted_tokens.rb, line 100 def to_plain_text @plain_text end