diff --git a/.travis.yml b/.travis.yml index d94d86d..1aebe60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,10 @@ sudo: false language: ruby cache: bundler +os: + - linux + - osx + rvm: - ruby-head - 2.6.5 @@ -15,7 +19,9 @@ gemfile: - gemfiles/openssl_2_0.gemfile - gemfiles/openssl_default.gemfile -before_install: gem install bundler -v '~> 2.0' +before_install: + - gem install bundler -v '~> 2.0' + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./script/setup-osx; else sudo ./script/setup-linux; fi matrix: fast_finish: true diff --git a/Gemfile b/Gemfile index 62f1c83..4ae369f 100644 --- a/Gemfile +++ b/Gemfile @@ -6,3 +6,7 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } # Specify your gem's dependencies in cose.gemspec gemspec + +# TODO: Remove this once libcbor gem is released with +# https://github.com/PJK/libcbor-ruby/pull/10 +gem "libcbor", github: "PJK/libcbor-ruby" diff --git a/README.md b/README.md index e84259e..9086ee9 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,21 @@ Ruby implementation of RFC [8152](https://tools.ietf.org/html/rfc8152) CBOR Obje [![Gem](https://img.shields.io/gem/v/cose.svg?style=flat-square)](https://rubygems.org/gems/cose) [![Travis](https://img.shields.io/travis/cedarcode/cose-ruby.svg?style=flat-square)](https://travis-ci.org/cedarcode/cose-ruby) +## Prerequisites + +### OSX + +``` +brew tap pjk/libcbor +brew install libcbor +``` + +### Linux (APT) + +``` +apt-get install libcbor-dev +``` + ## Installation Add this line to your application's Gemfile: diff --git a/cose.gemspec b/cose.gemspec index e157011..6172cac 100644 --- a/cose.gemspec +++ b/cose.gemspec @@ -31,7 +31,7 @@ Gem::Specification.new do |spec| spec.required_ruby_version = ">= 2.3" - spec.add_dependency "cbor", "~> 0.5.9" + spec.add_dependency "libcbor", "~> 0.1.0" spec.add_development_dependency "appraisal", "~> 2.2.0" spec.add_development_dependency "bundler", ">= 1.17", "< 3" diff --git a/gemfiles/openssl_2_0.gemfile b/gemfiles/openssl_2_0.gemfile index 3bc7e9f..241e963 100644 --- a/gemfiles/openssl_2_0.gemfile +++ b/gemfiles/openssl_2_0.gemfile @@ -2,6 +2,7 @@ source "https://rubygems.org" +gem "libcbor", git: "https://github.com/PJK/libcbor-ruby" gem "openssl", "~> 2.0.0" gemspec path: "../" diff --git a/gemfiles/openssl_2_1.gemfile b/gemfiles/openssl_2_1.gemfile index 67541a0..e15597f 100644 --- a/gemfiles/openssl_2_1.gemfile +++ b/gemfiles/openssl_2_1.gemfile @@ -2,6 +2,7 @@ source "https://rubygems.org" +gem "libcbor", git: "https://github.com/PJK/libcbor-ruby" gem "openssl", "~> 2.1.0" gemspec path: "../" diff --git a/gemfiles/openssl_default.gemfile b/gemfiles/openssl_default.gemfile index 095e660..16705c8 100644 --- a/gemfiles/openssl_default.gemfile +++ b/gemfiles/openssl_default.gemfile @@ -2,4 +2,6 @@ source "https://rubygems.org" +gem "libcbor", git: "https://github.com/PJK/libcbor-ruby" + gemspec path: "../" diff --git a/gemfiles/openssl_head.gemfile b/gemfiles/openssl_head.gemfile index 1174fa6..9912358 100644 --- a/gemfiles/openssl_head.gemfile +++ b/gemfiles/openssl_head.gemfile @@ -2,6 +2,7 @@ source "https://rubygems.org" +gem "libcbor", git: "https://github.com/PJK/libcbor-ruby" gem "openssl", git: "https://github.com/ruby/openssl" gemspec path: "../" diff --git a/lib/cbor.rb b/lib/cbor.rb new file mode 100644 index 0000000..68569e3 --- /dev/null +++ b/lib/cbor.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +require "libcbor/all" diff --git a/lib/cose/security_message.rb b/lib/cose/security_message.rb index 431e9d6..1872580 100644 --- a/lib/cose/security_message.rb +++ b/lib/cose/security_message.rb @@ -14,12 +14,12 @@ class SecurityMessage def self.deserialize(cbor) decoded = CBOR.decode(cbor) - if decoded.is_a?(CBOR::Tagged) - if respond_to?(:tag) && tag != decoded.tag + if decoded.is_a?(CBOR::Tag) + if respond_to?(:tag) && tag != decoded.value raise(COSE::Error, "Invalid CBOR tag") end - decoded = decoded.value + decoded = decoded.item end from_array(decoded) diff --git a/script/setup-linux b/script/setup-linux new file mode 100755 index 0000000..1b7e150 --- /dev/null +++ b/script/setup-linux @@ -0,0 +1,10 @@ +#!/bin/sh + +set -x + +if ! apt-cache show libcbor-dev >> /dev/null; then + add-apt-repository ppa:yubico/stable -y + apt-get update -q +fi + +apt-get install libcbor-dev -y diff --git a/script/setup-osx b/script/setup-osx new file mode 100755 index 0000000..e49e177 --- /dev/null +++ b/script/setup-osx @@ -0,0 +1,6 @@ +#!/bin/sh + +set -x + +brew tap pjk/libcbor +brew install libcbor diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a5aa333..5555383 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -17,7 +17,7 @@ end def create_security_message(protected_headers, unprotected_headers, *args, cbor_tag: 0) - CBOR::Tagged.new(cbor_tag, [CBOR.encode(protected_headers), unprotected_headers, *args]).to_cbor + CBOR::Tag.new(cbor_tag, [CBOR.encode(protected_headers), unprotected_headers, *args]).to_cbor end def wg_examples(relative_glob)