Class: COSE::Key::EC2
Constant Summary collapse
- CRV =
-1
- X =
-2
- Y =
-3
- D =
-4
- ES256 =
-7
- ES384 =
-35
- ES512 =
-36
- P256 =
1
- P384 =
2
- P521 =
3
Constants inherited from COSE::Key
ALG, BASE_IV, KID, KTY, KTY_EC2, KTY_OKP, KTY_RSA, KTY_SYMMETRIC, OPS
Instance Attribute Summary collapse
-
#crv ⇒ Object
Returns the value of attribute crv.
-
#d ⇒ Object
Returns the value of attribute d.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Attributes inherited from COSE::Key
#alg, #base_iv, #kid, #kty, #ops, #raw
Instance Method Summary collapse
- #curve_name ⇒ Object
- #digest ⇒ Object
-
#initialize(attrs = {}) ⇒ EC2
constructor
A new instance of EC2.
- #to_key ⇒ Object
Methods inherited from COSE::Key
decode, detect, #to_pem, #to_s, #to_text
Constructor Details
Instance Attribute Details
#crv ⇒ Object
Returns the value of attribute crv.
17 18 19 |
# File 'lib/cose/key/ec2.rb', line 17 def crv @crv end |
#d ⇒ Object
Returns the value of attribute d.
17 18 19 |
# File 'lib/cose/key/ec2.rb', line 17 def d @d end |
#x ⇒ Object
Returns the value of attribute x.
17 18 19 |
# File 'lib/cose/key/ec2.rb', line 17 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
17 18 19 |
# File 'lib/cose/key/ec2.rb', line 17 def y @y end |
Instance Method Details
#curve_name ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cose/key/ec2.rb', line 27 def curve_name case crv when P256 'prime256v1' when P384 'secp384r1' when P521 'secp521r1' else raise 'Unknown Curve' end end |
#digest ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/cose/key/ec2.rb', line 40 def digest case alg when ES256 OpenSSL::Digest::SHA256 when ES384 OpenSSL::Digest::SHA384 when ES512 OpenSSL::Digest::SHA512 else raise 'Unknown Algorithm' end.new end |
#to_key ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/cose/key/ec2.rb', line 53 def to_key key = OpenSSL::PKey::EC.new curve_name key.private_key = OpenSSL::BN.new(d, 2) if d key.public_key = OpenSSL::PKey::EC::Point.new( OpenSSL::PKey::EC::Group.new(curve_name), OpenSSL::BN.new([ '04' + x.unpack('H*').first + y.unpack('H*').first ].pack('H*'), 2) ) key end |