lib/xmlsec.rb in nokogiri-xmlsec-instructure-0.9.6 vs lib/xmlsec.rb in nokogiri-xmlsec-instructure-0.9.7
- old
+ new
@@ -59,16 +59,12 @@
# Examples:
#
# # encrypt with a public key and optional key name
# doc.encrypt! key: 'public-key', name: 'name'
#
- def encrypt! opts
- if opts[:key]
- encrypt_with_key opts[:name].to_s, opts[:key], opts.select { |key, _| key != :key && key != :name }
- else
- raise "public :key is required for encryption"
- end
+ def encrypt!(key:, name: nil, **opts)
+ root.encrypt_with(key: key, name: name, **opts)
self
end
# Decrypts the current document, then returns it.
#
@@ -87,9 +83,14 @@
self
end
end
class Nokogiri::XML::Node
+ def encrypt_with(key:, name: nil, **opts)
+ raise ArgumentError("public :key is required for encryption") unless key
+ encrypt_with_key(name, key, opts)
+ end
+
def decrypt_with(opts)
raise 'inadequate options specified for decryption' unless opts[:key]
parent = self.parent
previous = self.previous