Module: Facturae::Xades::Utils
- Included in:
- KeyInfo, ObjectInfo, SignedInfo, Signer
- Defined in:
- lib/facturae/xades/utils.rb
Overview
Utility methods for generating random IDs and encoding data in Base64.
Instance Method Summary collapse
-
#base64_encode(data) ⇒ Object
-
#base64_encode_raw(data) ⇒ Object
-
#calculate_sha512_digest(data) ⇒ Object
-
#create_xml_element(doc, name, content = nil, attributes = {}) ⇒ Object
-
#create_xml_node_with_algorithm(doc, name, algorithm) ⇒ Object
-
#rand_id ⇒ Object
Instance Method Details
#base64_encode(data) ⇒ Object
16 17 18 19 |
# File 'lib/facturae/xades/utils.rb', line 16 def base64_encode(data) digest_bytes = OpenSSL::Digest::SHA512.digest(data) Base64.strict_encode64(digest_bytes) end |
#base64_encode_raw(data) ⇒ Object
21 22 23 |
# File 'lib/facturae/xades/utils.rb', line 21 def base64_encode_raw(data) Base64.strict_encode64(data) end |
#calculate_sha512_digest(data) ⇒ Object
25 26 27 |
# File 'lib/facturae/xades/utils.rb', line 25 def calculate_sha512_digest(data) OpenSSL::Digest::SHA512.digest(data) end |
#create_xml_element(doc, name, content = nil, attributes = {}) ⇒ Object
29 30 31 32 33 |
# File 'lib/facturae/xades/utils.rb', line 29 def create_xml_element(doc, name, content = nil, attributes = {}) element = doc.create_element(name, content) attributes.each { |key, value| element[key] = value } element end |
#create_xml_node_with_algorithm(doc, name, algorithm) ⇒ Object
35 36 37 |
# File 'lib/facturae/xades/utils.rb', line 35 def create_xml_node_with_algorithm(doc, name, algorithm) create_xml_element(doc, name, nil, { "Algorithm" => algorithm }) end |
#rand_id ⇒ Object
11 12 13 14 |
# File 'lib/facturae/xades/utils.rb', line 11 def rand_id # SecureRandom.alphanumeric(6) SecureRandom.uuid end |