{"id":13879041,"url":"https://github.com/cedarcode/cose-ruby","last_synced_at":"2025-04-29T05:32:08.133Z","repository":{"id":42878994,"uuid":"136669029","full_name":"cedarcode/cose-ruby","owner":"cedarcode","description":"Ruby implementation of RFC 8152 CBOR Object Signing and Encryption (COSE)","archived":false,"fork":false,"pushed_at":"2025-02-21T19:18:03.000Z","size":307,"stargazers_count":17,"open_issues_count":5,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-16T06:30:35.397Z","etag":null,"topics":["cbor","cose","cose-key","rfc","ruby","signing"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/cose","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cedarcode.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null}},"created_at":"2018-06-08T21:49:54.000Z","updated_at":"2025-02-21T19:05:27.000Z","dependencies_parsed_at":"2022-09-06T05:22:38.221Z","dependency_job_id":null,"html_url":"https://github.com/cedarcode/cose-ruby","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedarcode%2Fcose-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedarcode%2Fcose-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedarcode%2Fcose-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedarcode%2Fcose-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cedarcode","download_url":"https://codeload.github.com/cedarcode/cose-ruby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251444691,"owners_count":21590556,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cbor","cose","cose-key","rfc","ruby","signing"],"created_at":"2024-08-06T08:02:07.825Z","updated_at":"2025-04-29T05:32:07.850Z","avatar_url":"https://github.com/cedarcode.png","language":"Ruby","readme":"# cose-ruby\n\nRuby implementation of RFC [8152](https://tools.ietf.org/html/rfc8152) CBOR Object Signing and Encryption (COSE)\n\n[![Gem](https://img.shields.io/gem/v/cose.svg?style=flat-square\u0026color=informational)](https://rubygems.org/gems/cose)\n[![Actions Build](https://github.com/cedarcode/cose-ruby/workflows/build/badge.svg)](https://github.com/cedarcode/cose-ruby/actions)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'cose'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install cose\n\n## Usage\n\n### Key Objects\n\n#### Deserialization (from CBOR to Ruby objects)\n\n```ruby\ncbor_data = \"...\"\n\nkey = COSE::Key.deserialize(cbor_data)\n```\n\nOnce you have a `COSE::Key` instance you can either access key parameters directly and/or convert it to an\n`OpenSSL::PKey::PKey` instance (if supported for the key type) for operating with it\n(encrypting/decrypting, signing/verifying, etc).\n\n```ruby\n# Convert to an OpenSSL::PKey::PKey\nif key.respond_to?(:to_pkey)\n  openssl_pkey = key.to_pkey\nend\n\n# Access COSE key parameters\ncase key\nwhen COSE::Key::OKP\n  key.crv\n  key.x\n  key.d\nwhen COSE::Key::EC2\n  key.crv\n  key.x\n  key.y\n  key.d\nwhen COSE::Key::RSA\n  key.n\n  key.e\n  key.d\n  key.p\n  key.q\n  key.dp\n  key.dq\n  key.qinv\nwhen COSE::Key::Symmetric\n  key.k\nend\n```\n\nIf you already know which COSE key type is encoded in the CBOR data, then:\n\n```ruby\nokp_key_cbor = \"...\"\n\ncose_okp_key = COSE::Key::OKP.deserialize(okp_key_cbor)\n\ncose_okp_key.crv\ncose_okp_key.x\ncose_okp_key.d\n```\n\n```ruby\nec2_key_cbor = \"...\"\n\ncose_ec2_key = COSE::Key::EC2.deserialize(ec2_key_cbor)\n\ncose_ec2_key.crv\ncose_ec2_key.x\ncose_ec2_key.y\ncose_ec2_key.d\n\n# or\n\nec_pkey = cose_ec2_key.to_pkey # Instance of an OpenSSL::PKey::EC\n```\n\n```ruby\nsymmetric_key_cbor = \"...\"\n\ncose_symmetric_key = COSE::Key::Symmetric.deserialize(symmetric_key_cbor)\n\ncose_symmetric_key.k\n```\n\n```ruby\nrsa_key_cbor = \"...\"\n\ncose_rsa_key = COSE::Key::RSA.deserialize(rsa_key_cbor)\n\ncose_rsa_key.n\ncose_rsa_key.e\ncose_rsa_key.d\ncose_rsa_key.p\ncose_rsa_key.q\ncose_rsa_key.dp\ncose_rsa_key.dq\ncose_rsa_key.qinv\n\n# or\n\nrsa_pkey = cose_rsa_key.to_pkey # Instance of an OpenSSL::PKey::RSA\n```\n\n#### Serialization (from Ruby objects to CBOR)\n\n```ruby\nec_pkey = OpenSSL::PKey::EC.new(\"prime256v1\").generate_key\n\ncose_ec2_key_cbor = COSE::Key.serialize(ec_pkey)\n```\n\n```ruby\nrsa_pkey = OpenSSL::PKey::RSA.new(2048)\n\ncose_rsa_key_cbor = COSE::Key.serialize(rsa_pkey)\n```\n\n### Signing Objects\n\n#### COSE_Sign\n\n```ruby\ncbor_data = \"...\"\n\nsign = COSE::Sign.deserialize(cbor_data)\n\n# Verify by doing (key should be a COSE::Key):\nsign.verify(key)\n\n# or, if externally supplied authenticated data exists:\nsign.verify(key, external_aad)\n\n# Then access payload\nsign.payload\n```\n\n#### COSE_Sign1\n\n```ruby\ncbor_data = \"...\"\n\nsign1 = COSE::Sign1.deserialize(cbor_data)\n\n# Verify by doing (key should be a COSE::Key):\nsign1.verify(key)\n\n# or, if externally supplied authenticated data exists:\nsign1.verify(key, external_aad)\n\n# Then access payload\nsign1.payload\n```\n\n### MAC Objects\n\n#### COSE_Mac\n\n```ruby\ncbor_data = \"...\"\n\nmac = COSE::Mac.deserialize(cbor_data)\n\n# Verify by doing (key should be a COSE::Key::Symmetric):\nmac.verify(key)\n\n# or, if externally supplied authenticated data exists:\nmac.verify(key, external_aad)\n\n# Then access payload\nmac.payload\n```\n\n#### COSE_Mac0\n\n```ruby\ncbor_data = \"...\"\n\nmac0 = COSE::Mac0.deserialize(cbor_data)\n\n# Verify by doing (key should be a COSE::Key::Symmetric):\nmac0.verify(key)\n\n# or, if externally supplied authenticated data exists:\nmac0.verify(key, external_aad)\n\n# Then access payload\nmac0.payload\n```\n\n### Encryption Objects\n\n#### COSE_Encrypt\n\n```ruby\ncbor_data = \"...\"\n\nencrypt = COSE::Encrypt.deserialize(cbor_data)\n\nencrypt.protected_headers\nencrypt.unprotected_headers\nencrypt.ciphertext\n\nencrypt.recipients.each do |recipient|\n  recipient.protected_headers\n  recipient.unprotected_headers\n  recipient.ciphertext\n\n  if recipient.recipients\n    recipient.recipients.each do |recipient|\n      recipient.protected_headers\n      recipient.unprotected_headers\n      recipient.ciphertext\n    end\n  end\nend\n```\n\n#### COSE_Encrypt0\n\n```ruby\ncbor_data = \"...\"\n\nencrypt0 = COSE::Encrypt0.deserialize(cbor_data)\n\nencrypt0.protected_headers\nencrypt0.unprotected_headers\nencrypt0.ciphertext\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/cedarcode/cose-ruby.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcedarcode%2Fcose-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcedarcode%2Fcose-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcedarcode%2Fcose-ruby/lists"}