Class: EC::Signature
- Inherits:
-
Object
- Object
- EC::Signature
- Defined in:
- lib/elliptic/signature.rb
Instance Attribute Summary collapse
-
#r ⇒ Object
readonly
Returns the value of attribute r.
-
#s ⇒ Object
readonly
Returns the value of attribute s.
Class Method Summary collapse
- .decode_base64(str) ⇒ Object (also: from_base64)
- .decode_der(der) ⇒ Object (also: from_der)
Instance Method Summary collapse
-
#initialize(r, s) ⇒ Signature
constructor
A new instance of Signature.
- #to_base64 ⇒ Object
- #to_der ⇒ Object
Constructor Details
#initialize(r, s) ⇒ Signature
Returns a new instance of Signature.
24 25 26 |
# File 'lib/elliptic/signature.rb', line 24 def initialize(r, s) @r, @s = r, s end |
Instance Attribute Details
#r ⇒ Object (readonly)
Returns the value of attribute r.
23 24 25 |
# File 'lib/elliptic/signature.rb', line 23 def r @r end |
#s ⇒ Object (readonly)
Returns the value of attribute s.
23 24 25 |
# File 'lib/elliptic/signature.rb', line 23 def s @s end |
Class Method Details
.decode_base64(str) ⇒ Object Also known as: from_base64
12 13 14 |
# File 'lib/elliptic/signature.rb', line 12 def self.decode_base64( str ) decode_der( Base64.decode64( str ) ) end |
.decode_der(der) ⇒ Object Also known as: from_der
5 6 7 8 9 10 |
# File 'lib/elliptic/signature.rb', line 5 def self.decode_der( der ) asn1 = OpenSSL::ASN1.decode( der ) r = asn1.value[0].value.to_i s = asn1.value[1].value.to_i new(r, s) end |
Instance Method Details
#to_base64 ⇒ Object
36 37 38 |
# File 'lib/elliptic/signature.rb', line 36 def to_base64 Base64.encode64( to_der ).gsub("\n", '' ) end |
#to_der ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/elliptic/signature.rb', line 28 def to_der asn1 = OpenSSL::ASN1::Sequence.new [ OpenSSL::ASN1::Integer.new( @r ), OpenSSL::ASN1::Integer.new( @s ), ] asn1.to_der end |