gitlab-cbor 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +25 -0
  3. data/.gitlab-ci.yml +44 -0
  4. data/.travis.yml +24 -0
  5. data/CHANGELOG.md +30 -0
  6. data/ChangeLog +106 -0
  7. data/Gemfile +11 -0
  8. data/README.rdoc +191 -0
  9. data/Rakefile +97 -0
  10. data/ci/test.rb +31 -0
  11. data/doclib/cbor/buffer.rb +193 -0
  12. data/doclib/cbor/core_ext.rb +133 -0
  13. data/doclib/cbor/error.rb +14 -0
  14. data/doclib/cbor/packer.rb +133 -0
  15. data/doclib/cbor/simple.rb +15 -0
  16. data/doclib/cbor/tagged.rb +16 -0
  17. data/doclib/cbor/unpacker.rb +138 -0
  18. data/doclib/cbor.rb +80 -0
  19. data/ext/cbor/buffer.c +693 -0
  20. data/ext/cbor/buffer.h +484 -0
  21. data/ext/cbor/buffer_class.c +561 -0
  22. data/ext/cbor/buffer_class.h +41 -0
  23. data/ext/cbor/cbor.h +69 -0
  24. data/ext/cbor/compat.h +147 -0
  25. data/ext/cbor/core_ext.c +199 -0
  26. data/ext/cbor/core_ext.h +35 -0
  27. data/ext/cbor/extconf.rb +29 -0
  28. data/ext/cbor/packer.c +169 -0
  29. data/ext/cbor/packer.h +370 -0
  30. data/ext/cbor/packer_class.c +345 -0
  31. data/ext/cbor/packer_class.h +40 -0
  32. data/ext/cbor/rbinit.c +57 -0
  33. data/ext/cbor/renamer.h +56 -0
  34. data/ext/cbor/rmem.c +103 -0
  35. data/ext/cbor/rmem.h +118 -0
  36. data/ext/cbor/sysdep.h +139 -0
  37. data/ext/cbor/sysdep_endian.h +59 -0
  38. data/ext/cbor/sysdep_types.h +55 -0
  39. data/ext/cbor/unpacker.c +787 -0
  40. data/ext/cbor/unpacker.h +135 -0
  41. data/ext/cbor/unpacker_class.c +483 -0
  42. data/ext/cbor/unpacker_class.h +39 -0
  43. data/gitlab-cbor.gemspec +27 -0
  44. data/lib/cbor/version.rb +3 -0
  45. data/lib/cbor.rb +6 -0
  46. data/spec/buffer_io_spec.rb +260 -0
  47. data/spec/buffer_spec.rb +576 -0
  48. data/spec/cases.cbor +0 -0
  49. data/spec/cases.cbor_stream +0 -0
  50. data/spec/cases.json +1 -0
  51. data/spec/cases.msg +0 -0
  52. data/spec/cases_compact.msg +0 -0
  53. data/spec/cases_spec.rb +39 -0
  54. data/spec/format_spec.rb +603 -0
  55. data/spec/packer_spec.rb +127 -0
  56. data/spec/random_compat.rb +24 -0
  57. data/spec/spec_helper.rb +68 -0
  58. data/spec/unpacker_spec.rb +260 -0
  59. metadata +189 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ea5eb261daf6b702e032472b8be3b3d3949c5d516f1625b674c193c95bcbd404
4
+ data.tar.gz: 242826a0aae1fe136ca397ae643104294c5a60e8f95f280ec47cecfa1713e418
5
+ SHA512:
6
+ metadata.gz: 3ecd0c2c1f49069fde1345ba89c3098464a475e6ff364c7202bf7a30122a2154e711a6f7ff42167aef98066a95b1ec0e56be73b9fc194ed5795bae52bdf30472
7
+ data.tar.gz: 7ee9b2549b5ff605f27a01778450171529a74f9daa7325d7069a4d4441ed956171a7e2c0ecb25cb817819698a71d50e94eb49f3fa3666c08c3e61fb8189eb282
data/.gitignore ADDED
@@ -0,0 +1,25 @@
1
+ *.o
2
+ *.so
3
+ *.gem
4
+ *.class
5
+ .bundle
6
+ Gemfile.lock
7
+ pkg
8
+ test/debug.log
9
+ *~
10
+ /rdoc
11
+ tmp
12
+ .classpath
13
+ .project
14
+ .settings
15
+ /nbproject/private/
16
+ ext/java/build
17
+ ext/java/msgpack.jar
18
+ spec/bench*
19
+ lib/cbor/cbor.bundle
20
+ TAGS
21
+ .yardoc
22
+ doc
23
+ ext/cbor/Makefile
24
+ *.bundle
25
+ mkmf.log
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,44 @@
1
+ # CI for gitlab-cbor, GitLab's security fork of the cbor gem.
2
+ #
3
+ # Builds the native extension, installs the gem, and runs a smoke test that
4
+ # verifies the security behavior and a core round-trip. The publish job is
5
+ # intentionally manual and tag-only; the gem is NOT published automatically
6
+ # while the fix is under embargo.
7
+
8
+ stages:
9
+ - test
10
+ - release
11
+
12
+ .ruby-versions: &ruby-versions
13
+ parallel:
14
+ matrix:
15
+ - RUBY_IMAGE: ["ruby:3.2", "ruby:3.3", "ruby:3.4"]
16
+
17
+ build-and-test:
18
+ stage: test
19
+ image: $RUBY_IMAGE
20
+ <<: *ruby-versions
21
+ script:
22
+ - ruby -v
23
+ - gem build gitlab-cbor.gemspec
24
+ - gem install ./gitlab-cbor-*.gem --no-document
25
+ - ruby ci/test.rb
26
+
27
+ # Publishing is held until the fix is public. Run manually on a tag once the
28
+ # advisory is out; set GEM_HOST_API_KEY (and GEM_HOST for a private registry)
29
+ # in protected CI/CD variables.
30
+ publish:
31
+ stage: release
32
+ image: ruby:3.3
33
+ rules:
34
+ - if: '$CI_COMMIT_TAG'
35
+ when: manual
36
+ allow_failure: true
37
+ script:
38
+ - gem build gitlab-cbor.gemspec
39
+ - |
40
+ if [ -z "${GEM_HOST_API_KEY:-}" ]; then
41
+ echo "GEM_HOST_API_KEY is not set; refusing to publish." >&2
42
+ exit 1
43
+ fi
44
+ - gem push gitlab-cbor-*.gem ${GEM_HOST:+--host "$GEM_HOST"}
data/.travis.yml ADDED
@@ -0,0 +1,24 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.10
5
+ - 2.2.10
6
+ - 2.3.8
7
+ - 2.4.6
8
+ - 2.5.5
9
+ - 2.6.3
10
+ - ruby-head
11
+ matrix:
12
+ allow_failures:
13
+ - rvm: 2.0.0
14
+ - rvm: 2.1.10
15
+ - rvm: 2.2.10
16
+ - rvm: ruby-head
17
+
18
+ gemfile:
19
+ - Gemfile
20
+
21
+ script: "bundle exec rake spec"
22
+
23
+ notifications:
24
+ irc: "irc.freenode.org#coap"
data/CHANGELOG.md ADDED
@@ -0,0 +1,30 @@
1
+ # Changelog (GitLab fork)
2
+
3
+ `gitlab-cbor` is GitLab's fork of the [`cbor`](https://rubygems.org/gems/cbor)
4
+ gem. It tracks an upstream release and carries a small number of changes that
5
+ are not yet available upstream. The gem installs the same files and defines the
6
+ same `CBOR` module, so it is a drop-in replacement:
7
+
8
+ ```ruby
9
+ gem "gitlab-cbor", require: "cbor"
10
+ ```
11
+
12
+ ## 1.0.0
13
+
14
+ First release of the fork. Based on upstream cbor 0.6.1.1.
15
+
16
+ - Do not reconstruct object-constructing CBOR tags by default.
17
+ Decoding tag 35 (regular expression) and tag 32 (URI) previously built a
18
+ `Regexp` or `URI` from the decoded value. Because `CBOR.decode` is
19
+ commonly run on input from untrusted sources, decoding should not build
20
+ those objects on its own. These tags now decode to a generic
21
+ `CBOR::Tagged` value. A caller that trusts the source can opt back in per
22
+ tag:
23
+
24
+ ```ruby
25
+ CBOR.decode(data) # => CBOR::Tagged
26
+ CBOR.decode(data, reconstruct_from_tags: [CBOR::TAG_REGEXP]) # => Regexp
27
+ CBOR.decode(data, reconstruct_from_tags: [CBOR::TAG_URI]) # => URI
28
+ ```
29
+
30
+ Tag 0/1 (time) is unchanged; it is a plain value conversion.
data/ChangeLog ADDED
@@ -0,0 +1,106 @@
1
+ 2016-04-11 Carsten Bormann <cabo@tzi.org>
2
+
3
+ * 0.5.9.1: Fix WIN32 problem inherited from upstream
4
+
5
+ 2014-12-13 Carsten Bormann <cabo@tzi.org>
6
+
7
+ * 0.5.9.0: Upstream fixes; prepare for Ruby 2.2 (use GC-able
8
+ symbols for :keys_as_symbols, use rb_integer_pack if available)
9
+
10
+ 2014-12-12 Carsten Bormann <cabo@tzi.org>
11
+
12
+ * 0.5.8.0: Upstream fixes (including {symbolize_keys: true} as an
13
+ alternative for :keys_as_symbols); README updates.
14
+
15
+ 2014-02-09 Carsten Bormann <cabo@tzi.org>
16
+
17
+ * 0.5.6.4: Add more checking for bare indefinite breaks and
18
+ non-strings inside indefinite strings.
19
+
20
+ 2013-08-17 Carsten Bormann <cabo@tzi.org>
21
+
22
+ * First version of CBOR variant of this code.
23
+
24
+ 2013-09-23 version 0.5.6:
25
+
26
+ * Fixed "can't modify frozen String" exception in Unpacker with ruby 2.1.0-dev
27
+ * Getting work with Ruby v2.0 on Windows (Thank you @thegreendroid)
28
+ * Fixed EOFError handling in Unpacker
29
+
30
+
31
+ 2013-05-12 version 0.5.5:
32
+
33
+ * Fixed SEGV problem in to_msgpack
34
+ * Fixed a possible race condition in MessagePack.load when it loads data from IO
35
+ * mingw32 package includes binary for ruby-2.0.0
36
+
37
+
38
+ 2013-03-15 version 0.5.4:
39
+
40
+ * Added missing MessagePack::Unpacker#reset method
41
+
42
+
43
+ 2013-02-14 version 0.5.3:
44
+
45
+ * Fixed segfault problem on Buffer#clear (reuse rmem internal fragment optimization)
46
+ * Fixed segfault problem on Buffer (rmem free code)
47
+
48
+
49
+ 2013-02-07 version 0.5.2:
50
+
51
+ * Fixed invalid pack/unpack on 32bit architecture such as Win32
52
+ * Disable rmem on Rubinius because rmem is not thread safe
53
+
54
+
55
+ 2012-12-23 version 0.5.1:
56
+
57
+ * Fixed compile error with Rubinius 2.0.0-dev
58
+ * Optimized msgpack_packer_write_hash for Rubinius
59
+
60
+
61
+ 2012-12-20 version 0.5.0:
62
+
63
+ * Rewrote all code and improved performance significantly
64
+ * Added MessagePack::Buffer class
65
+ * Added MessagePack::Packer class
66
+ * Added Packer#buffer and Unpacker#buffer accessors which return MessagePack::Buffer
67
+ * Added Packer#write_{array,map}_header and Unpacker#read_{array,map}_header methods
68
+ * Added Packer#write_nil and Unpacker#skip_nil methods
69
+ * Added Packer#write -> #pack alias and Unpacker#read method
70
+ * Added exception classes - UnpackError, MalformedFormatError, StackError and TypeError
71
+ * Added MessagePack.dup -> .pack and MessagePack.load -> .unpack aliases
72
+ * Added Packer#empty?, #size and #clear methods
73
+ * Added Packer#write_to(io) method to flush serialized data to IO efficiently
74
+ * Added Unpacker#skip method to skip an object efficiently
75
+ * Removed obsoleted Unpacker#fill, #execute, #execute_limit, #finished? and #data methods
76
+ * Removed obsoleted Unapcker#stream and #stream= methods. Use unpacker.buffer.io instead
77
+
78
+
79
+ 2012-05-05 version 0.4.7:
80
+
81
+ * Fixed serialization of double values on ARM OABI architectures
82
+ * Fixed byteorder problem on big-endian platforms
83
+ * Don't use MRI internals in the Ruby extension for Rubinius
84
+ * Detect whether st.h is present and don't use RUBY_VM as the condition for
85
+ Rubinius
86
+
87
+ 2011-08-08 version 0.4.6:
88
+
89
+ * Fixed compile error problem on Mac OS X Lion
90
+
91
+ 2011-05-09 version 0.4.5:
92
+
93
+ * Improves compatibility with JRuby
94
+
95
+ 2010-11-28 version 0.4.4:
96
+
97
+ * Adds Unpacker#feed_each method
98
+ * Improves compatibility with Rubinius
99
+ * Improves compatibility with ruby-1.8.5
100
+ * Encodings of String instances to UTF-8 on Ruby 1.9
101
+
102
+ 2010-06-29 version 0.4.3:
103
+
104
+ * Adds MessagePack::VERSION constant
105
+ * Fixes SEGV problem caused by GC bug at MessagePack_Unpacker_mark
106
+
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org/'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem "rake"
7
+ gem 'rake-compiler'
8
+ gem 'rspec'
9
+ gem 'json'
10
+ gem 'yard'
11
+ end
data/README.rdoc ADDED
@@ -0,0 +1,191 @@
1
+ = CBOR for Ruby
2
+
3
+ This is a Ruby implementation of the CBOR[http://cbor.io] encoding, based on
4
+ the (polished) high-performance msgpack-ruby code.
5
+
6
+ Documentation will follow, but generally, if you replace MessagePack
7
+ and msgpack with CBOR and cbor in the text cited from MessagePack
8
+ below, you will be on the right track. For a starter:
9
+
10
+ require 'cbor'
11
+ s = [1, 2, 33.5, 4].to_cbor #=> "\x84\x01\x02\xF9P0\x04"
12
+ CBOR.decode(s) #=> [1, 2, 33.5, 4]
13
+
14
+ Use RubyGems to install:
15
+
16
+ gem install cbor
17
+
18
+ CBOR is an object representation format defined by the IETF[http://ietf.org].
19
+ The specification[http://tools.ietf.org/html/rfc8949]
20
+ is an IETF Standards-Track specification
21
+ and has been published as RFC 8949 (superseding the older RFC 7049).
22
+
23
+ This is all based on wonderful work by frsyuki, and I have no idea how
24
+ to acknowledge him appropriately. This gem is not intended to fork or
25
+ supersede MessagePack[http://msgpack.org], which has a vibrant
26
+ ecosystem. It is just making use of the high-quality code that is
27
+ available in this community. If MessagePack works for you, go for it.
28
+ If you need CBOR, you need this.
29
+
30
+ Todos:
31
+
32
+ * This code has not yet been fully optimized, so it is still a few
33
+ percent slower than msgpack-ruby.
34
+
35
+ * Properly document things, in particular the classes CBOR::Simple and
36
+ CBOR::Tagged. If you check out the source, you can +rake+ +doc+ to
37
+ get some documentation in the directory +doc+ (see +index.html+ there).
38
+
39
+ * Cover more rubies.
40
+ * \[✔✔✔✔] tested on MRI (1.9.3, 2.0.0, 2.1.10, 2.2.10, 2.3.7, 2.4.4 and 2.5.1).
41
+ * (\[✔] There now also is some basic MRI 1.8.7 compatibility, however 1.8.7 does not support differentiation between byte and text strings.)
42
+ * \[✔] tested on Rubinius 2.4.1.
43
+ * \[_] Publish the pure-ruby version and make it work the same way on JRuby.
44
+
45
+ * Find and implement good ways to offer CBOR's indefinite length
46
+ ("streaming") capability at the Ruby API level. (Decoding is fully
47
+ supported, just no streaming or indefinite length encoding.)
48
+
49
+ * Rename some of the internals from msgpack to cbor. Right now, much
50
+ of the code still uses the name msgpack in its identifiers, to
51
+ facilitate merging upstream fixes. (The msgpack and cbor gems
52
+ coexist nicely in one MRI instance due to the magic in +renamer.h+.)
53
+
54
+ Same Apache 2.0 License applies to the changes as to the original.
55
+ For the changes:
56
+
57
+ Author:: Carsten Bormann <cabo@tzi.org>
58
+ Copyright:: Copyright (c) 2013, 2014 Carsten Bormann
59
+ License:: Apache License, Version 2.0
60
+
61
+ {<img src="https://travis-ci.org/cabo/cbor-ruby.svg?branch=master" />}[https://travis-ci.org/cabo/cbor-ruby] {<img src="https://badge.fury.io/rb/cbor.svg" alt="Gem Version" />}[http://badge.fury.io/rb/cbor]
62
+
63
+ For the original, see below.
64
+
65
+ = MessagePack
66
+
67
+ MessagePack[http://msgpack.org] is an efficient binary serialization format.
68
+ It lets you exchange data among multiple languages like JSON but it's faster and smaller.
69
+ For example, small integers (like flags or error code) are encoded into a single byte,
70
+ and typical short strings only require an extra byte in addition to the strings themselves.
71
+
72
+ If you ever wished to use JSON for convenience (storing an image with metadata) but could
73
+ not for technical reasons (binary data, size, speed...), MessagePack is a perfect replacement.
74
+
75
+ require 'msgpack'
76
+ msg = [1,2,3].to_msgpack #=> "\x93\x01\x02\x03"
77
+ MessagePack.unpack(msg) #=> [1,2,3]
78
+
79
+ Use RubyGems to install:
80
+
81
+ gem install msgpack
82
+
83
+ or build msgpack-ruby and install:
84
+
85
+ bundle
86
+ rake
87
+ gem install --local pkg/msgpack
88
+
89
+
90
+ = Use cases
91
+
92
+ * Store objects efficiently serialized by msgpack on memcached or Redis
93
+ * In fact Redis supports msgpack in EVAL-scripts[http://redis.io/commands/eval]
94
+ * Upload data in efficient format from mobile devices such as smartphones
95
+ * MessagePack works on iPhone/iPad and Android. See also Objective-C[https://github.com/msgpack/msgpack-objectivec] and Java[https://github.com/msgpack/msgpack-java] implementations
96
+ * Design a portable protocol to communicate with embedded devices
97
+ * Check also Fluentd[http://fluentd.org/] which is a log collector which uses msgpack for the log format (they say it uses JSON but actually it's msgpack, which is compatible with JSON)
98
+ * Exchange objects between software components written in different languages
99
+ * You'll need a flexible but efficient format so that components exchange objects while keeping compatibility
100
+
101
+
102
+ = Portability
103
+
104
+ MessagePack for Ruby should run on x86, ARM, PowerPC, SPARC and other CPU architectures.
105
+
106
+ And it works with MRI (CRuby) and Rubinius.
107
+ Patches to improve portability is highly welcomed.
108
+
109
+
110
+ = Serializing objects
111
+
112
+ Use *MessagePack.pack* or *to_msgpack*:
113
+
114
+ require 'msgpack'
115
+ msg = MessagePack.pack(obj) # or
116
+ msg = obj.to_msgpack
117
+
118
+ == Streaming serialization
119
+
120
+ Packer provides advanced API to serialize objects in streaming style:
121
+
122
+ # serialize a 2-element array [e1, e2]
123
+ pk = MessagePack::Packer.new(io)
124
+ pk.write_array_header(2).write(e1).write(e2).flush
125
+
126
+ See {API reference}[http://ruby.msgpack.org/MessagePack/Packer.html] for details.
127
+
128
+ = Deserializing objects
129
+
130
+ Use *MessagePack.unpack*:
131
+
132
+ require 'msgpack'
133
+ obj = MessagePack.unpack(msg)
134
+
135
+ == Streaming deserialization
136
+
137
+ Unpacker provides advanced API to deserialize objects in streaming style:
138
+
139
+ # deserialize objects from an IO
140
+ u = MessagePack::Unpacker.new(io)
141
+ u.each do |obj|
142
+ # ...
143
+ end
144
+
145
+ or event-driven style which works well with EventMachine:
146
+
147
+ # event-driven deserialization
148
+ def on_read(data)
149
+ @u ||= MessagePack::Unpacker.new
150
+ @u.feed_each(data) {|obj|
151
+ # ...
152
+ }
153
+ end
154
+
155
+ See {API reference}[http://ruby.msgpack.org/MessagePack/Unpacker.html] for details.
156
+
157
+
158
+ = Buffer API
159
+
160
+ MessagePack for Ruby provides a buffer API so that you can read or write data by hand, not via Packer or Unpacker API.
161
+
162
+ This {MessagePack::Buffer}[http://ruby.msgpack.org/MessagePack/Buffer.html] is backed with a fixed-length shared memory pool which is very fast for small data (<= 4KB),
163
+ and has zero-copy capability which significantly affects performance to handle large binary data.
164
+
165
+ = How to build and run tests
166
+
167
+ Before building msgpack, you need to install bundler and dependencies.
168
+
169
+ gem install bundler
170
+ bundle install
171
+
172
+ Then, you can run the tasks as follows:
173
+
174
+ * Build
175
+
176
+ bundle exec rake build
177
+
178
+ * Run tests
179
+
180
+ bundle exec rake spec
181
+
182
+ * Generating docs
183
+
184
+ bundle exec rake doc
185
+
186
+ = Copyright
187
+
188
+ Author:: Sadayuki Furuhashi <frsyuki@gmail.com>
189
+ Copyright:: Copyright (c) 2008-2013 Sadayuki Furuhashi
190
+ License:: Apache License, Version 2.0
191
+
data/Rakefile ADDED
@@ -0,0 +1,97 @@
1
+
2
+ require 'bundler'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ require 'fileutils'
6
+
7
+ require 'rspec/core'
8
+ require 'rspec/core/rake_task'
9
+ require 'yard'
10
+
11
+ RSpec::Core::RakeTask.new(:spec) do |t|
12
+ t.rspec_opts = ["-c", "-f documentation"]
13
+ t.rspec_opts << "-Ilib"
14
+ t.pattern = 'spec/**/*_spec.rb'
15
+ t.verbose = true
16
+ end
17
+
18
+ task :spec => :compile
19
+
20
+ desc 'Run RSpec code examples and measure coverage'
21
+ task :coverage do |t|
22
+ ENV['SIMPLE_COV'] = '1'
23
+ Rake::Task["spec"].invoke
24
+ end
25
+
26
+ desc 'Generate YARD document'
27
+ YARD::Rake::YardocTask.new(:doc) do |t|
28
+ t.files = ['lib/cbor/version.rb','doclib/**/*.rb']
29
+ t.options = []
30
+ t.options << '--debug' << '--verbose' if $trace
31
+ end
32
+
33
+ spec = eval File.read("cbor.gemspec")
34
+
35
+ if RUBY_PLATFORM =~ /java/
36
+ require 'rake/javaextensiontask'
37
+
38
+ Rake::JavaExtensionTask.new('cbor', spec) do |ext|
39
+ ext.ext_dir = 'ext/java'
40
+ #jruby_home = RbConfig::CONFIG['prefix']
41
+ #jars = ["#{jruby_home}/lib/jruby.jar"] + FileList['lib/*.jar']
42
+ #ext.classpath = jars.map { |x| File.expand_path x }.join ':'
43
+ end
44
+
45
+ else
46
+ require 'rake/extensiontask'
47
+
48
+ Rake::ExtensionTask.new('cbor', spec) do |ext|
49
+ ext.cross_compile = true
50
+ ext.lib_dir = File.join(*['lib', 'cbor', ENV['FAT_DIR']].compact)
51
+ #ext.cross_platform = 'i386-mswin32'
52
+ end
53
+ end
54
+
55
+ CLEAN.include('lib/cbor/*.jar')
56
+ CLEAN.include('lib/cbor/cbor.*')
57
+
58
+ task :default => :build
59
+
60
+
61
+ ###
62
+ ## Cross compile memo
63
+ ##
64
+ ## Ubuntu Ubuntu 10.04.1 LTS
65
+ ##
66
+ #
67
+ ### install mingw32 cross compiler with w64 support
68
+ # sudo apt-get install gcc-mingw32
69
+ # sudo apt-get install mingw-w64
70
+ #
71
+ ### install rbenv
72
+ # git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
73
+ # echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
74
+ # echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
75
+ # exec $SHELL -l
76
+ #
77
+ ### install cross-compiled ruby 2.0.0
78
+ # rbenv install 2.0.0-p0
79
+ # gem install rake-compiler
80
+ # rake-compiler cross-ruby VERSION=2.0.0-p0
81
+ #
82
+ ### install cross-compiled ruby 1.9.3
83
+ # rbenv install 1.9.3-p327
84
+ # gem install rake-compiler
85
+ # rake-compiler cross-ruby VERSION=1.9.3-p327
86
+ #
87
+ ### install cross-compiled ruby 1.8.7
88
+ # rbenv install 1.8.7-p371
89
+ # gem install rake-compiler
90
+ # rake-compiler cross-ruby VERSION=1.8.7-p371
91
+ #
92
+ ### build gem
93
+ # rbenv shell 1.8.7-p371
94
+ # gem install bundler && bundle
95
+ # rake cross native gem RUBY_CC_VERSION=1.8.7:1.9.3:2.0.0
96
+ #
97
+
data/ci/test.rb ADDED
@@ -0,0 +1,31 @@
1
+ # Smoke test run in CI against the installed gitlab-cbor gem. Exercises the
2
+ # security behavior (object-constructing tags are opt-in) plus a core
3
+ # round-trip, the same way a consumer loads it: require "cbor".
4
+ require "cbor"
5
+ require "time"
6
+ require "uri"
7
+
8
+ failures = []
9
+ check = lambda do |name, got, want|
10
+ failures << "#{name}: got #{got.inspect}, want #{want.inspect}" unless got == want
11
+ end
12
+
13
+ re = "\xd8\x23\x63foo".b # tag 35, "foo"
14
+ uri = "\xd8\x20\x6bhttp://a.ex".b # tag 32, "http://a.ex"
15
+ tm = "\xc1\x1a\x51\x4b\x67\xb0".b # tag 1, epoch
16
+
17
+ check.call("constants", [CBOR::TAG_REGEXP, CBOR::TAG_URI], [35, 32])
18
+ check.call("default regexp -> Tagged", CBOR.decode(re), CBOR::Tagged.new(35, "foo"))
19
+ check.call("default uri -> Tagged", CBOR.decode(uri), CBOR::Tagged.new(32, "http://a.ex"))
20
+ check.call("opt-in regexp", CBOR.decode(re, reconstruct_from_tags: [CBOR::TAG_REGEXP]), /foo/)
21
+ check.call("opt-in uri", CBOR.decode(uri, reconstruct_from_tags: [CBOR::TAG_URI]), URI.parse("http://a.ex"))
22
+ check.call("uri stays Tagged without opt-in", CBOR.decode(uri, reconstruct_from_tags: [CBOR::TAG_REGEXP]), CBOR::Tagged.new(32, "http://a.ex"))
23
+ check.call("time always reconstructed", CBOR.decode(tm), Time.at(1363896240))
24
+ check.call("core round-trip", CBOR.decode({ "a" => [1, 2, "x"] }.to_cbor), { "a" => [1, 2, "x"] })
25
+
26
+ if failures.empty?
27
+ puts "OK: all #{8} checks passed (gitlab-cbor #{Gem.loaded_specs['gitlab-cbor']&.version})"
28
+ else
29
+ warn "FAILED:\n " + failures.join("\n ")
30
+ exit 1
31
+ end