Class: Xml::Kit::KeyInfo

Inherits:
Object
  • Object
show all
Includes:
Templatable
Defined in:
lib/xml/kit/key_info.rb,
lib/xml/kit/key_info/key_value.rb,
lib/xml/kit/key_info/rsa_key_value.rb,
lib/xml/kit/key_info/retrieval_method.rb

Overview

An implementation of the KeyInfo element. www.w3.org/TR/xmldsig-core1/#sec-KeyInfo

Since:

  • 0.3.0

Defined Under Namespace

Classes: KeyValue, RSAKeyValue, RetrievalMethod

Instance Attribute Summary collapse

Attributes included from Templatable

#digest_method, #embed_signature, #encrypt, #encryption_certificate, #signature_method, #signing_key_pair

Instance Method Summary collapse

Methods included from Templatable

#encrypt_data_for, #encrypt_key_for, #encrypt_with, #encryption_for, #render, #sign_with, #signature_for, #to_xml

Constructor Details

#initialize(x509: nil, encrypted_key: nil) {|_self| ... } ⇒ KeyInfo

Returns a new instance of KeyInfo.

Yields:

  • (_self)

Yield Parameters:

Since:

  • 0.3.0



19
20
21
22
23
# File 'lib/xml/kit/key_info.rb', line 19

def initialize(x509: nil, encrypted_key: nil)
  @encrypted_key = encrypted_key
  @x509_data = x509
  yield self if block_given?
end

Instance Attribute Details

#encrypted_keyObject

Since:

  • 0.3.0



17
18
19
# File 'lib/xml/kit/key_info.rb', line 17

def encrypted_key
  @encrypted_key
end

#key_nameObject

Since:

  • 0.3.0



15
16
17
# File 'lib/xml/kit/key_info.rb', line 15

def key_name
  @key_name
end

#x509_dataObject

Since:

  • 0.3.0



16
17
18
# File 'lib/xml/kit/key_info.rb', line 16

def x509_data
  @x509_data
end

Instance Method Details

#asymmetric_cipher(algorithm: Crypto::RsaCipher::ALGORITHM) ⇒ Object

Since:

  • 0.3.0



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/xml/kit/key_info.rb', line 25

def asymmetric_cipher(algorithm: Crypto::RsaCipher::ALGORITHM)
  return encrypted_key.asymmetric_cipher if encrypted_key

  if x509_data
    return Crypto.cipher_for(
      derive_algorithm_from(x509_data.public_key),
      x509_data.public_key
    )
  end

  super(algorithm: algorithm)
end

#key_valueObject

Since:

  • 0.3.0



44
45
46
# File 'lib/xml/kit/key_info.rb', line 44

def key_value
  @key_value ||= KeyValue.new
end

#retrieval_methodObject

Since:

  • 0.3.0



48
49
50
# File 'lib/xml/kit/key_info.rb', line 48

def retrieval_method
  @retrieval_method ||= RetrievalMethod.new
end

#subject_key_identifierObject

Since:

  • 0.3.0



52
53
54
55
56
57
# File 'lib/xml/kit/key_info.rb', line 52

def subject_key_identifier
  ski = x509_data.extensions.find { |x| x.oid == 'subjectKeyIdentifier' }
  return if ski.nil?

  Base64.strict_encode64(ski.value)
end

#symmetric_cipherObject

Since:

  • 0.3.0



38
39
40
41
42
# File 'lib/xml/kit/key_info.rb', line 38

def symmetric_cipher
  return super if encrypted_key.nil?

  encrypted_key.symmetric_cipher
end