Class: EllipticCurve::Signature
- Inherits:
-
Object
- Object
- EllipticCurve::Signature
- Defined in:
- lib/signature.rb
Instance Attribute Summary collapse
-
#r ⇒ Object
readonly
Returns the value of attribute r.
-
#recoveryId ⇒ Object
readonly
Returns the value of attribute recoveryId.
-
#s ⇒ Object
readonly
Returns the value of attribute s.
Class Method Summary collapse
- ._fromString(string, recoveryId = nil) ⇒ Object
- .fromBase64(string, recoveryByte = false) ⇒ Object
- .fromDer(string, recoveryByte = false) ⇒ Object
Instance Method Summary collapse
- #_toString ⇒ Object
-
#initialize(r, s, recoveryId = nil) ⇒ Signature
constructor
A new instance of Signature.
- #toBase64(withRecoveryId = false) ⇒ Object
- #toDer(withRecoveryId = false) ⇒ Object
Constructor Details
#initialize(r, s, recoveryId = nil) ⇒ Signature
Returns a new instance of Signature.
5 6 7 8 9 |
# File 'lib/signature.rb', line 5 def initialize(r, s, recoveryId=nil) @r = r @s = s @recoveryId = recoveryId end |
Instance Attribute Details
#r ⇒ Object (readonly)
Returns the value of attribute r.
3 4 5 |
# File 'lib/signature.rb', line 3 def r @r end |
#recoveryId ⇒ Object (readonly)
Returns the value of attribute recoveryId.
3 4 5 |
# File 'lib/signature.rb', line 3 def recoveryId @recoveryId end |
#s ⇒ Object (readonly)
Returns the value of attribute s.
3 4 5 |
# File 'lib/signature.rb', line 3 def s @s end |
Class Method Details
._fromString(string, recoveryId = nil) ⇒ Object
46 47 48 49 |
# File 'lib/signature.rb', line 46 def self._fromString(string, recoveryId=nil) @r, @s = Utils::Der.parse(string)[0] return Signature.new(@r, @s, recoveryId) end |
.fromBase64(string, recoveryByte = false) ⇒ Object
34 35 36 37 |
# File 'lib/signature.rb', line 34 def self.fromBase64(string, recoveryByte=false) der = Utils::Binary.byteStringFromBase64(string) return self.fromDer(der, recoveryByte) end |
.fromDer(string, recoveryByte = false) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/signature.rb', line 24 def self.fromDer(string, recoveryByte=false) @recoveryId = nil if recoveryByte @recoveryId = string[0].ord - 27 string = string[1..-1] end hexadecimal = Utils::Binary.hexFromByteString(string) return self._fromString(hexadecimal, @recoveryId) end |
Instance Method Details
#_toString ⇒ Object
39 40 41 42 43 44 |
# File 'lib/signature.rb', line 39 def _toString return Utils::Der.encodeConstructed( Utils::Der.encodePrimitive(Utils::Der::DerFieldType.integer, @r), Utils::Der.encodePrimitive(Utils::Der::DerFieldType.integer, @s) ) end |
#toBase64(withRecoveryId = false) ⇒ Object
20 21 22 |
# File 'lib/signature.rb', line 20 def toBase64(withRecoveryId=false) return Utils::Binary.base64FromByteString(self.toDer(withRecoveryId)) end |
#toDer(withRecoveryId = false) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/signature.rb', line 11 def toDer(withRecoveryId=false) hexadecimal = self._toString encodedSequence = Utils::Binary.byteStringFromHex(hexadecimal) if not withRecoveryId return encodedSequence end return (27 + @recoveryId).chr + encodedSequence end |