diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2017-04-06 14:34:09 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2017-12-14 17:51:26 +0900 |
commit | 60ce7ea71f6de7ada86ca809b5418afa8230f891 (patch) | |
tree | 1646b9ae3a02968babf8707470c0b2a012d38686 /lib/openssl | |
parent | 717f4b9bb3e6efbeb55b724222eaab8e83c100ef (diff) | |
download | ruby-openssl-60ce7ea71f6de7ada86ca809b5418afa8230f891.tar.gz |
pkey/ec: add support for octet string encoding of EC pointky/pkey-ec-point-octet-string
Add a new method named PKey::EC#to_octet_string that returns the octet
string representation of the curve point. PKey::EC::Point#to_bn, which
have already existed and is similar except that an instance of
OpenSSL::BN is returned, is rewritten in Ruby.
PKey::EC::Point#initialize now takes String as the second argument in
the PKey::EC::Point.new(group, encoded_point) form.
Also, update the tests to use #to_octet_string instead of #to_bn for
better readability.
Diffstat (limited to 'lib/openssl')
-rw-r--r-- | lib/openssl/pkey.rb | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/openssl/pkey.rb b/lib/openssl/pkey.rb index dcedd849..8a547c34 100644 --- a/lib/openssl/pkey.rb +++ b/lib/openssl/pkey.rb @@ -1,3 +1,25 @@ # frozen_string_literal: false -module OpenSSL +#-- +# Ruby/OpenSSL Project +# Copyright (C) 2017 Ruby/OpenSSL Project Authors +#++ + +module OpenSSL::PKey + if defined?(EC) + class EC::Point + # :call-seq: + # point.to_bn([conversion_form]) -> OpenSSL::BN + # + # Returns the octet string representation of the EC point as an instance of + # OpenSSL::BN. + # + # If _conversion_form_ is not given, the _point_conversion_form_ attribute + # set to the group is used. + # + # See #to_octet_string for more information. + def to_bn(conversion_form = group.point_conversion_form) + OpenSSL::BN.new(to_octet_string(conversion_form), 2) + end + end + end end |