lib/cose/key.rb in cose-0.4.1 vs lib/cose/key.rb in cose-0.5.0
- old
+ new
@@ -1,13 +1,25 @@
require "cbor"
require "cose/key/ec2"
require "cose/key/rsa"
require "cose/key/symmetric"
+require "openssl"
module COSE
class UnknownKeyType < StandardError; end
module Key
+ def self.serialize(pkey)
+ case pkey
+ when OpenSSL::PKey::EC, OpenSSL::PKey::EC::Point
+ COSE::Key::EC2.from_pkey(pkey).serialize
+ when OpenSSL::PKey::RSA
+ COSE::Key::RSA.from_pkey(pkey).serialize
+ else
+ raise "Unsupported serialization of #{pkey.class} object"
+ end
+ end
+
def self.deserialize(data)
map = CBOR.decode(data)
case map[Base::LABEL_KTY]
when COSE::Key::EC2::KTY_EC2