Class: Xml::Kit::EncryptedData

Inherits:
Object
  • Object
show all
Defined in:
lib/xml/kit/encrypted_data.rb

Overview

An implementation of the EncryptedKey element. www.w3.org/TR/xmlenc-core1/#sec-EncryptedData

Since:

  • 0.3.0

Direct Known Subclasses

Encryption

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_xml, id: Id.generate, symmetric_cipher: nil, asymmetric_cipher: nil, key_info: nil) ⇒ EncryptedData

Returns a new instance of EncryptedData.

Since:

  • 0.3.0



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/xml/kit/encrypted_data.rb', line 15

def initialize(raw_xml,
               id: Id.generate,
               symmetric_cipher: nil,
               asymmetric_cipher: nil,
               key_info: nil)
  @id = id
  @symmetric_cipher = symmetric_cipher ||
    key_info.try(:symmetric_cipher) ||
    Xml::Kit::Crypto::SymmetricCipher.new
  @symmetric_cipher_value = Base64.strict_encode64(
    @symmetric_cipher.encrypt(raw_xml)
  )
  @key_info = key_info ||
    create_key_info_for(@symmetric_cipher, asymmetric_cipher)
end

Instance Attribute Details

#idObject (readonly)

Since:

  • 0.3.0



10
11
12
# File 'lib/xml/kit/encrypted_data.rb', line 10

def id
  @id
end

#key_infoObject (readonly)

Since:

  • 0.3.0



11
12
13
# File 'lib/xml/kit/encrypted_data.rb', line 11

def key_info
  @key_info
end

#symmetric_cipherObject (readonly)

Since:

  • 0.3.0



12
13
14
# File 'lib/xml/kit/encrypted_data.rb', line 12

def symmetric_cipher
  @symmetric_cipher
end

#symmetric_cipher_valueObject (readonly)

Since:

  • 0.3.0



13
14
15
# File 'lib/xml/kit/encrypted_data.rb', line 13

def symmetric_cipher_value
  @symmetric_cipher_value
end

Instance Method Details

#render(model, options) ⇒ Object

Since:

  • 0.3.0



35
36
37
# File 'lib/xml/kit/encrypted_data.rb', line 35

def render(model, options)
  ::Xml::Kit::Template.new(model).to_xml(options)
end

#to_xml(xml: ::Builder::XmlMarkup.new) ⇒ Object

Since:

  • 0.3.0



31
32
33
# File 'lib/xml/kit/encrypted_data.rb', line 31

def to_xml(xml: ::Builder::XmlMarkup.new)
  ::Xml::Kit::Template.new(self).to_xml(xml: xml)
end