lib/chamber/file.rb in chamber-2.11.0 vs lib/chamber/file.rb in chamber-2.12.0

- old
+ new

@@ -1,10 +1,11 @@ # frozen_string_literal: true require 'pathname' require 'yaml' require 'erb' +require 'chamber/files/signature' ### # Internal: Represents a single file containing settings information in a given # file set. # @@ -101,9 +102,31 @@ end write(file_contents) end # rubocop:enable Metrics/LineLength + + def sign + signature_key_contents = decryption_keys[:signature] + + fail ArgumentError, 'You asked to sign your settings files but no signature key was found. Run `chamber init --signature` to generate one.' \ + unless signature_key_contents + + signature = Files::Signature.new(to_s, read, signature_key_contents) + + signature.write + end + + def verify + signature_key_contents = encryption_keys[:signature] + + fail ArgumentError, 'You asked to verify your settings files but no signature key was found. Run `chamber init --signature` to generate one.' \ + unless signature_key_contents + + signature = Files::Signature.new(to_s, read, signature_key_contents) + + signature.verify + end private def secure_prefix '_secure_'