class EC::PublicKey
Public Class Methods
convert( *args, **kwargs )
click to toggle source
# File lib/elliptic/public_key.rb, line 5 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
decode_base64( str )
click to toggle source
todo/check: only use (allow) base64 for
der (binary)-encoded? why? why not?
# File lib/elliptic/public_key.rb, line 20 def self.decode_base64( str ) new( Base64.decode64(str)); end
Also aliased as: from_base64
decode_der( str )
click to toggle source
# File lib/elliptic/public_key.rb, line 16 def self.decode_der( str ) new( str ); end
Also aliased as: from_der
decode_pem( str )
click to toggle source
# File lib/elliptic/public_key.rb, line 15 def self.decode_pem( str ) new( str ); end
Also aliased as: from_pem
new( *args, group: nil )
click to toggle source
# File lib/elliptic/public_key.rb, line 29 def initialize( *args, group: nil ) if args.size == 2 ## assume (x,y) raw integer points @pt = Point.new( *args, group: group ) point = @pt.to_ec_point ## convert point to openssl (native) class @pkey = OpenSSL::PKey::EC.new( point.group ) @pkey.public_key = point elsif args[0].is_a?( Point ) || args[0].is_a?( OpenSSL::PKey::EC::Point ) ## "restore" public key (only) from point for verify ## - OpenSSL::PKey::EC::Point ## assume public key only (restore pkey object for verify?) ## - Point 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 ## note: (auto)get group from point @pkey = OpenSSL::PKey::EC.new( point.group ) @pkey.public_key = point else ## assume string in pem/der/base64 @pkey = OpenSSL::PKey::EC.new( args[0] ) end end
Public Instance Methods
group()
click to toggle source
more helpers for debugging / internals
# File lib/elliptic/public_key.rb, line 78 def group() @pkey.group; end
point()
click to toggle source
# File lib/elliptic/public_key.rb, line 57 def point ## cache returned point - why? why not? @pt ||= Point.new( @pkey.public_key ) @pt end
private?()
click to toggle source
# File lib/elliptic/public_key.rb, line 80 def private?() @pkey.private?; end
public?()
click to toggle source
# File lib/elliptic/public_key.rb, line 81 def public?() @pkey.public?; end
to_base64()
click to toggle source
# File lib/elliptic/public_key.rb, line 66 def to_base64() Base64.encode64( to_der ); end
to_der()
click to toggle source
# File lib/elliptic/public_key.rb, line 65 def to_der() @pkey.to_der; end
to_pem()
click to toggle source
# File lib/elliptic/public_key.rb, line 64 def to_pem() @pkey.to_pem; end
to_text()
click to toggle source
# File lib/elliptic/public_key.rb, line 79 def to_text() @pkey.to_text; end
verify?( message, signature )
click to toggle source
# File lib/elliptic/public_key.rb, line 69 def verify?( message, signature ) signature_der = signature.to_der @pkey.dsa_verify_asn1( message, signature_der ) end
Also aliased as: valid_signature?