Class: EC::PublicKey
- Inherits:
-
Object
- Object
- EC::PublicKey
- Defined in:
- lib/elliptic.rb
Class Method Summary collapse
Instance Method Summary collapse
- #group ⇒ Object
-
#initialize(*args, group: nil) ⇒ PublicKey
constructor
A new instance of PublicKey.
- #point ⇒ Object
-
#public? ⇒ Boolean
todo/check: keep - needed? - why? why not?.
-
#to_text ⇒ Object
helpers for debugging.
- #verify?(message, signature) ⇒ Boolean (also: #valid_signature?)
Constructor Details
#initialize(*args, group: nil) ⇒ PublicKey
Returns a new instance of PublicKey.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/elliptic.rb', line 108 def initialize( *args, group: nil ) point = if args.size == 2 ## assume (x,y) raw integer points @pt = Point.new( *args, group: group ) @pt.to_ec_point ## convert point to openssl (native) class else ## "restore" public key (only) from point for verify ## - OpenSSL::PKey::EC::Point ## assume public key only (restore pkey object for verify?) ## - Point if args[0].is_a?( Point ) @pt = args[0] @pt.to_ec_point else args[0] ## assume it is already OpenSSL::PKey::EC::Point end end ## note: (auto)get group from point @pkey = OpenSSL::PKey::EC.new( point.group ) @pkey.public_key = point end |
Class Method Details
.convert(*args, **kwargs) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/elliptic.rb', line 98 def self.convert( *args, **kwargs ) if args.size==1 && args[0].is_a?( PublicKey ) args[0] ## pass through as is (already a public key) else new( *args, group: kwargs[:group] ) end end |
Instance Method Details
#group ⇒ Object
129 |
# File 'lib/elliptic.rb', line 129 def group() @pkey.group; end |
#point ⇒ Object
132 133 134 135 136 |
# File 'lib/elliptic.rb', line 132 def point ## cache returned point - why? why not? @pt ||= Point.new( @pkey.public_key ) @pt end |
#public? ⇒ Boolean
todo/check: keep - needed? - why? why not?
148 |
# File 'lib/elliptic.rb', line 148 def public?() @pkey.public?; end |
#to_text ⇒ Object
helpers for debugging
147 |
# File 'lib/elliptic.rb', line 147 def to_text() @pkey.to_text; end |
#verify?(message, signature) ⇒ Boolean Also known as: valid_signature?
140 141 142 143 |
# File 'lib/elliptic.rb', line 140 def verify?( , signature ) signature_der = signature.to_der @pkey.dsa_verify_asn1( , signature_der ) end |