module COSE::Key
Constants
Public Class Methods
cbor_decode(data)
click to toggle source
# File lib/cose/key.rb, line 51 def self.cbor_decode(data) CBOR.decode(data) rescue CBOR::MalformedFormatError, EOFError, FloatDomainError, RegexpError, TypeError, URI::InvalidURIError raise COSE::MalformedKeyError, "Malformed CBOR key input" end
deserialize(data)
click to toggle source
# File lib/cose/key.rb, line 32 def self.deserialize(data) map = cbor_decode(data) case map[Base::LABEL_KTY] when COSE::Key::OKP::KTY_OKP COSE::Key::OKP.from_map(map) when COSE::Key::EC2::KTY_EC2 COSE::Key::EC2.from_map(map) when COSE::Key::RSA::KTY_RSA COSE::Key::RSA.from_map(map) when COSE::Key::Symmetric::KTY_SYMMETRIC COSE::Key::Symmetric.from_map(map) when nil raise COSE::UnknownKeyType, "Missing required key type kty label" else raise COSE::UnknownKeyType, "Unsupported or unknown key type #{map[Base::LABEL_KTY]}" end end
from_pkey(pkey)
click to toggle source
# File lib/cose/key.rb, line 21 def self.from_pkey(pkey) case pkey when OpenSSL::PKey::EC, OpenSSL::PKey::EC::Point COSE::Key::EC2.from_pkey(pkey) when OpenSSL::PKey::RSA COSE::Key::RSA.from_pkey(pkey) else raise "Unsupported #{pkey.class} object" end end
serialize(pkey)
click to toggle source
# File lib/cose/key.rb, line 17 def self.serialize(pkey) from_pkey(pkey).serialize end