class Ansible::Vault::FileWriter
A class for writting the encrypted data into an Ansible
formatted file
@!attribute [r] path
@return [String] The path to write the file to, truncated before writing
@!attribute [rw] ciphertext
@return [String] The encrypted contents of the file.
@!attribute [rw] hmac
@return [String] The HMAC value for the ciphertext, calculated by an instance of {Encryptor}
@!attribute [rw] salt
@return [String] The salt value for the ciphertext, generated by an instance of {Encryptor}
Attributes
ciphertext[RW]
hmac[RW]
path[R]
salt[RW]
Public Class Methods
new(path)
click to toggle source
Construct a new FileWriter
@param [String] path The path to write the file out to.
# File lib/ansible/vault/file_writer.rb, line 22 def initialize(path) @path = path end
Public Instance Methods
write()
click to toggle source
Write out the encrypted contents of the file in the correct format.
@return [File] The closed file handle used to write the data out.
# File lib/ansible/vault/file_writer.rb, line 29 def write File.open(path, 'w') { |file| file.write(FILE_HEADER + "\n") file.write(encoded_body) } end
Private Instance Methods
encoded_body()
click to toggle source
# File lib/ansible/vault/file_writer.rb, line 38 def encoded_body encoded_ciphertext = BinASCII.hexlify(@ciphertext) encoded_salt = BinASCII.hexlify(@salt) raw_body = [encoded_salt, @hmac, encoded_ciphertext].join("\n") BinASCII.hexlify(raw_body).scan(/.{,80}/).join("\n") end