ordo 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 859241b0c0396d87392134cbcd910097b386c300
4
- data.tar.gz: 767bbecacd458fbd61d8b1faa61c529a83396cb6
3
+ metadata.gz: 04e607b11a82dde05b1b45e926adb043c9fb11f4
4
+ data.tar.gz: 002a998c4afb7e42ae674ab7c58bd1d48e9a1a15
5
5
  SHA512:
6
- metadata.gz: 2f10f47305efd9b0cc9b0598b28cc4f555239147f9dec543a6cb18dc7cc45e33457f739739d972f227a22007efdf7aaccac03f15c25b98d05d08772a6a9f28ad
7
- data.tar.gz: 5c3045c41570bdcbe9e93c42dc3227c79ecb77c6bc165260fce485d9900a8824c8ea61d9a0ebc7755e657b90bbda937d1dd725669219f03ff29e7cf804c23678
6
+ metadata.gz: ee6e1a1b1f838553726948af3fc34f2befa61df9d1ceb701c8027b315252bc867dc2f2a6497569f86d11ceac7b0f3694e15c5edf77fdf9f976b1d85bb3b53cb2
7
+ data.tar.gz: 709ed72d6d3f65028562aa59a28f57f22c647ff5af04d67f7aa56eb6c77806c01ac404185490524d0dfd915d6d60d6d7d58e3ee4ab70309779ecb3b07b247235
@@ -0,0 +1,7 @@
1
+ 0.0.2 (06-07-2014)
2
+ ------------------
3
+ * Support for base64 encoded message bodies
4
+
5
+ 0.0.1 (06-01-2014)
6
+ ------------------
7
+ * Initial release
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  ![ORDO: Ordered Representation for Distinguished Objects](https://raw.githubusercontent.com/cryptosphere/ordo/master/logo.png)
2
2
  =========================================================
3
3
 
4
+ [![Gem Version](https://badge.fury.io/rb/ordo.png)](http://rubygems.org/gems/ordo)
4
5
  [![Build Status](https://travis-ci.org/cryptosphere/ordo.png?branch=master)](https://travis-ci.org/cryptosphere/ordo)
5
6
  [![Code Climate](https://codeclimate.com/github/cryptosphere/ordo.png)](https://codeclimate.com/github/cryptosphere/ordo)
6
7
  [![Coverage
@@ -3,7 +3,7 @@
3
3
  require 'ordo/version'
4
4
  require 'ordo/message'
5
5
 
6
- # Ordered Representation of Distinguished Objects
6
+ # Ordered Representation for Distinguished Objects
7
7
  module ORDO
8
8
  # Couldn't parse the given message
9
9
  ParseError = Class.new(StandardError)
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'strscan'
4
+ require 'base64'
4
5
 
5
6
  module ORDO
6
7
  class Message
@@ -70,7 +71,14 @@ module ORDO
70
71
  end
71
72
 
72
73
  def parse_body
73
- @body = @scanner.rest
74
+ raw_body = @scanner.rest
75
+ encoding = @fields['Content-Transfer-Encoding']
76
+
77
+ @body = case encoding
78
+ when 'base64' then Base64.strict_decode64(raw_body)
79
+ when 'binary', NilClass then raw_body
80
+ else fail ArgumentError, "invalid message encoding: #{encoding}"
81
+ end
74
82
  end
75
83
 
76
84
  def parse_error(message)
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- # Ordered Representation of Distinguished Objects
3
+ # Ordered Representation for Distinguished Objects
4
4
  module ORDO
5
- VERSION = '0.0.1'
5
+ VERSION = '0.0.2'
6
6
  end
@@ -17,46 +17,69 @@ describe ORDO::Message::Parser do
17
17
  let(:example_body) { 'Some things are better left unread' }
18
18
  let(:example_message) { example_header + example_body }
19
19
 
20
- it 'parses messages' do
21
- parser = subject.parse(example_message)
20
+ let(:example_header64) { example_header.sub('binary', 'base64') }
21
+ let(:example_body64) { Base64.strict_encode64(example_body) }
22
+ let(:example_message64) { example_header64 + example_body64 }
22
23
 
23
- expect(parser.version).to eq example_version
24
- expect(parser.fields).to eq(
25
- 'Cipher' => example_cipher,
26
- 'Content-Length' => example_body.length.to_s,
27
- 'Content-Transfer-Encoding' => example_encoding
28
- )
24
+ context 'binary encoding' do
25
+ it 'parses messages' do
26
+ parser = subject.parse(example_message)
29
27
 
30
- expect(parser.body).to eq example_body
31
- end
28
+ expect(parser.version).to eq example_version
29
+ expect(parser.fields).to eq(
30
+ 'Cipher' => example_cipher,
31
+ 'Content-Length' => example_body.length.to_s,
32
+ 'Content-Transfer-Encoding' => example_encoding
33
+ )
32
34
 
33
- it 'raises ParseError if no ORDO MSG header found' do
34
- begin
35
- subject.parse('garbage')
36
- rescue ORDO::ParseError => ex # rubocop:disable all
35
+ expect(parser.body).to eq example_body
37
36
  end
37
+ end
38
+
39
+ context 'base64 encoding' do
40
+ it 'parses messages' do
41
+ parser = subject.parse(example_message64)
38
42
 
39
- expect(ex).to be_a ORDO::ParseError
40
- expect(ex.to_s).to match(/no.*header/)
43
+ expect(parser.version).to eq example_version
44
+ expect(parser.fields).to eq(
45
+ 'Cipher' => example_cipher,
46
+ 'Content-Length' => example_body.length.to_s,
47
+ 'Content-Transfer-Encoding' => 'base64'
48
+ )
49
+
50
+ expect(parser.body).to eq example_body
51
+ end
41
52
  end
42
53
 
43
- it 'raises ParseError if version is invalid' do
44
- begin
45
- subject.parse('---ORDO MSG vX---')
46
- rescue ORDO::ParseError => ex # rubocop:disable all
54
+ context 'parse errors' do
55
+ it 'raises ParseError if no ORDO MSG header found' do
56
+ begin
57
+ subject.parse('garbage')
58
+ rescue ORDO::ParseError => ex # rubocop:disable all
59
+ end
60
+
61
+ expect(ex).to be_a ORDO::ParseError
62
+ expect(ex.to_s).to match(/no.*header/)
47
63
  end
48
64
 
49
- expect(ex).to be_a ORDO::ParseError
50
- expect(ex.to_s).to match(/invalid version/)
51
- end
65
+ it 'raises ParseError if version is invalid' do
66
+ begin
67
+ subject.parse('---ORDO MSG vX---')
68
+ rescue ORDO::ParseError => ex # rubocop:disable all
69
+ end
52
70
 
53
- it 'raises ParseError if invalid fields are encountered' do
54
- begin
55
- subject.parse("---ORDO MSG v0---\r\nfoo: bar\r\n\r\n")
56
- rescue ORDO::ParseError => ex # rubocop:disable all
71
+ expect(ex).to be_a ORDO::ParseError
72
+ expect(ex.to_s).to match(/invalid version/)
57
73
  end
58
74
 
59
- expect(ex).to be_a ORDO::ParseError
60
- expect(ex.to_s).to match(/invalid.*field name/)
75
+ it 'raises ParseError if invalid fields are encountered' do
76
+ begin
77
+ subject.parse("---ORDO MSG v0---\r\nfoo: bar\r\n\r\n")
78
+ rescue ORDO::ParseError => ex # rubocop:disable all
79
+ end
80
+
81
+ expect(ex).to be_a ORDO::ParseError
82
+ expect(ex.to_s).to match(/invalid.*field name/)
83
+ end
61
84
  end
62
85
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ordo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Arcieri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-01 00:00:00.000000000 Z
11
+ date: 2014-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -77,6 +77,7 @@ files:
77
77
  - ".rspec"
78
78
  - ".rubocop.yml"
79
79
  - ".travis.yml"
80
+ - CHANGES.md
80
81
  - Gemfile
81
82
  - Guardfile
82
83
  - LICENSE.txt