README.md in cose-0.5.0 vs README.md in cose-0.6.0

- old
+ new

@@ -28,52 +28,69 @@ #### Deserialization (from CBOR to Ruby objects) ```ruby cbor_data = "..." -cose_key = COSE::Key.deserialize(cbor_data) +key = COSE::Key.deserialize(cbor_data) ``` Once you have a `COSE::Key` instance you can either access key parameters directly and/or convert it to an -`OpenSSL::PKey::PKey` instance for operating with it (encrypting/decrypting, signing/verifying, etc). +`OpenSSL::PKey::PKey` instance (if supported for the key type) for operating with it +(encrypting/decrypting, signing/verifying, etc). ```ruby # Convert to an OpenSSL::PKey::PKey -openssl_pkey = cose_key.to_pkey +if key.respond_to?(:to_pkey) + openssl_pkey = key.to_pkey +end # Access COSE key parameters case key +when COSE::Key::OKP + key.crv + key.x + key.d when COSE::Key::EC2 - key.curve - key.x_coordinate - key.y_coordinate - key.d_coordinate + key.crv + key.x + key.y + key.d when COSE::Key::RSA - key.modulus_n - key.public_exponent_e - key.private_exponent_d - key.prime_factor_p - key.prime_factor_q - key.d_p - key.d_q - key.q_inv + key.n + key.e + key.d + key.p + key.q + key.dp + key.dq + key.qinv when COSE::Key::Symmetric - key.key_value + key.k end ``` If you already know which COSE key type is encoded in the CBOR data, then: ```ruby +okp_key_cbor = "..." + +cose_okp_key = COSE::Key::OKP.deserialize(okp_key_cbor) + +cose_okp_key.crv +cose_okp_key.x +cose_okp_key.d +``` + +```ruby ec2_key_cbor = "..." cose_ec2_key = COSE::Key::EC2.deserialize(ec2_key_cbor) -cose_ec2_key.curve -cose_ec2_key.x_coordinate -cose_ec2_key.y_coordinate -cose_ec2_key.d_coordinate +cose_ec2_key.crv +cose_ec2_key.x +cose_ec2_key.y +cose_ec2_key.d # or ec_pkey = cose_ec2_key.to_pkey # Instance of an OpenSSL::PKey::EC ``` @@ -81,25 +98,25 @@ ```ruby symmetric_key_cbor = "..." cose_symmetric_key = COSE::Key::Symmetric.deserialize(symmetric_key_cbor) -cose_symmetric_key.key_value +cose_symmetric_key.k ``` ```ruby rsa_key_cbor = "..." cose_rsa_key = COSE::Key::RSA.deserialize(rsa_key_cbor) -cose_rsa_key.modulus_n -cose_rsa_key.public_exponent_e -cose_rsa_key.private_exponent_d -cose_rsa_key.prime_factor_p -cose_rsa_key.prime_factor_q -cose_rsa_key.d_p -cose_rsa_key.d_q -cose_rsa_key.q_inv +cose_rsa_key.n +cose_rsa_key.e +cose_rsa_key.d +cose_rsa_key.p +cose_rsa_key.q +cose_rsa_key.dp +cose_rsa_key.dq +cose_rsa_key.qinv # or rsa_pkey = cose_rsa_key.to_pkey # Instance of an OpenSSL::PKey::RSA ```