Class: PkiExpress::DigestAlgorithm

Inherits:
Object
  • Object
show all
Defined in:
lib/pki_express/digest_algorithm.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, oid, byte_length, api_model, xml_uri) ⇒ DigestAlgorithm

Returns a new instance of DigestAlgorithm.



12
13
14
15
16
17
18
# File 'lib/pki_express/digest_algorithm.rb', line 12

def initialize(name, oid, byte_length, api_model, xml_uri)
  @name = name
  @oid = oid
  @byte_length = byte_length
  @api_model = api_model
  @xml_uri = xml_uri
end

Instance Attribute Details

#api_modelObject

Returns the value of attribute api_model.



11
12
13
# File 'lib/pki_express/digest_algorithm.rb', line 11

def api_model
  @api_model
end

#byte_lengthObject

Returns the value of attribute byte_length.



11
12
13
# File 'lib/pki_express/digest_algorithm.rb', line 11

def byte_length
  @byte_length
end

#nameObject

Returns the value of attribute name.



11
12
13
# File 'lib/pki_express/digest_algorithm.rb', line 11

def name
  @name
end

#oidObject

Returns the value of attribute oid.



11
12
13
# File 'lib/pki_express/digest_algorithm.rb', line 11

def oid
  @oid
end

#xml_uriObject

Returns the value of attribute xml_uri.



11
12
13
# File 'lib/pki_express/digest_algorithm.rb', line 11

def xml_uri
  @xml_uri
end

Class Method Details

.get_instance_by_api_model(api_model) ⇒ Object



110
111
112
113
114
115
116
# File 'lib/pki_express/digest_algorithm.rb', line 110

def get_instance_by_api_model(api_model)
  algorithms = get_algorithms
  unless algorithms.select{|v| v.api_model.downcase == api_model.downcase}.empty?
    return algorithms.select{|v| v.api_model.downcase == api_model.downcase}.first
  end
  raise 'Unrecognized digest algorithm: ' + api_model
end

.get_instance_by_name(name) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/pki_express/digest_algorithm.rb', line 86

def get_instance_by_name(name)
  algorithms = get_algorithms
  unless algorithms.select{|v| v.name == name}.empty?
    return algorithms.select{|v| v.name == name}.first
  end
  raise 'Unrecognized digest algorithm name: ' + name
end

.get_instance_by_oid(oid) ⇒ Object



94
95
96
97
98
99
100
# File 'lib/pki_express/digest_algorithm.rb', line 94

def get_instance_by_oid(oid)
  algorithms = get_algorithms
  unless algorithms.select{|v| v.oid == oid}.empty?
    return algorithms.select{|v| v.oid == oid}.first
  end
  raise 'Unrecognized digest algorithm oid: ' + oid
end

.get_instance_by_xml_uri(xml_uri) ⇒ Object



102
103
104
105
106
107
108
# File 'lib/pki_express/digest_algorithm.rb', line 102

def get_instance_by_xml_uri(xml_uri)
  algorithms = get_algorithms
  unless algorithms.select{|v| v.xml_uri == xml_uri}.empty?
    return algorithms.select{|v| v.xml_uri == xml_uri}.first
  end
  raise 'Unrecognized digest algorithm XML URI: ' + xml_uri
end

.md5Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pki_express/digest_algorithm.rb', line 20

def self.md5
  unless @md5
    @md5 = new(
      DigestAlgorithms::MD5,
      Oids::MD5,
      16,
      'md5',
      'http://www.w3.org/2001/04/xmldsig-more#md5')
  end
  @md5
end

.sha1Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pki_express/digest_algorithm.rb', line 32

def self.sha1
  unless @sha1
    @sha1 = new(
      DigestAlgorithms::SHA1,
      Oids::SHA1,
      20,
      'sha1',
      'http://www.w3.org/2000/09/xmldsig#sha1')
  end
  @sha1
end

.sha256Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/pki_express/digest_algorithm.rb', line 44

def self.sha256
  unless @sha256
    @sha256 = new(
      DigestAlgorithms::SHA256,
      Oids::SHA256,
      32,
      'sha256',
      'http://www.w3.org/2001/04/xmlenc#sha256')
  end
  @sha256
end

.sha384Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/pki_express/digest_algorithm.rb', line 56

def self.sha384
  unless @sha384
    @sha384 = new(
      DigestAlgorithms::SHA384,
      Oids::SHA384,
      48,
      'sha384',
      'http://www.w3.org/2001/04/xmldsig-more#sha384')
  end
  @sha384
end

.sha512Object



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/pki_express/digest_algorithm.rb', line 68

def self.sha512
  unless @sha512
    @sha512 = new(
      DigestAlgorithms::SHA512,
      Oids::SHA512,
      64,
      'sha512',
      'http://www.w3.org/2001/04/xmlenc#sha512')
  end
  @sha512
end