Module: COSE::Key

Defined in:
lib/cose/key.rb,
lib/cose/key/ec2.rb,
lib/cose/key/rsa.rb,
lib/cose/key/base.rb,
lib/cose/key/symmetric.rb

Defined Under Namespace

Classes: Base, EC2, RSA, Symmetric

Class Method Summary collapse

Class Method Details

.deserialize(data) ⇒ Object


22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cose/key.rb', line 22

def self.deserialize(data)
  map = CBOR.decode(data)

  case map[Base::LABEL_KTY]
  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)
  else
    raise UnknownKeyType, "Unsupported or unknown key type #{map[Base::LABEL_KTY]}"
  end
end

.serialize(pkey) ⇒ Object


11
12
13
14
15
16
17
18
19
20
# File 'lib/cose/key.rb', line 11

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