ciphr 0.0.2 → 0.0.4

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.
File without changes
@@ -1,49 +1,49 @@
1
- module Ciphr
2
- class Stream
3
- def initialize(reader)
4
- @reader = reader
5
- @buffer = ""
6
- @eof = false
7
- end
8
-
9
- def read(n=nil) #fix this
10
- if n
11
- init
12
- while @buffer.size < n && !@eof
13
- fill
14
- end
15
- if @buffer.size > 0
16
- ret = @buffer[0,n]
17
- @buffer = @buffer[n..-1] || ''
18
- else
19
- ret = nil
20
- end
21
- ret
22
- else
23
- buff = ""
24
- while chunk=read(256)
25
- buff+=chunk
26
- end
27
- buff
28
- end
29
- end
30
-
31
- def prepend(str)
32
- @buffer = str + @buffer
33
- end
34
-
35
- private
36
- def fill
37
- data = @reader.call
38
- @eof = true if !data
39
- @buffer = @buffer + data if data
40
- end
41
-
42
- def init #hack
43
- if !@init
44
- @init = true
45
- @reader = @reader.apply if @reader.respond_to?(:apply)
46
- end
47
- end
48
- end
49
- end
1
+ module Ciphr
2
+ class Stream
3
+ def initialize(reader)
4
+ @reader = reader
5
+ @buffer = ""
6
+ @eof = false
7
+ end
8
+
9
+ def read(n=nil) #fix this
10
+ if n
11
+ init
12
+ while @buffer.size < n && !@eof
13
+ fill
14
+ end
15
+ if @buffer.size > 0
16
+ ret = @buffer[0,n]
17
+ @buffer = @buffer[n..-1] || ''
18
+ else
19
+ ret = nil
20
+ end
21
+ ret
22
+ else
23
+ buff = ""
24
+ while chunk=read(256)
25
+ buff+=chunk
26
+ end
27
+ buff
28
+ end
29
+ end
30
+
31
+ def prepend(str)
32
+ @buffer = str + @buffer
33
+ end
34
+
35
+ private
36
+ def fill
37
+ data = @reader.call
38
+ @eof = true if !data
39
+ @buffer = @buffer + data if data
40
+ end
41
+
42
+ def init #hack
43
+ if !@init
44
+ @init = true
45
+ @reader = @reader.apply if @reader.respond_to?(:apply)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,3 +1,3 @@
1
1
  module Ciphr
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
Binary file
@@ -1,21 +1,21 @@
1
- require 'spec_helper'
2
- require 'ciphr'
3
-
4
- describe Ciphr do
5
- describe :transform do
6
- it "works for some simple test cases" do
7
- Ciphr.transform("md5 hex","").should be == "d41d8cd98f00b204e9800998ecf8427e"
8
- Ciphr.transform("b64 ~b64","foobar").should be == "foobar"
9
- Ciphr.transform("b2 b16 ~b16 ~b2","foobar").should be == "foobar"
10
- Ciphr.transform('"foobar"',"").should be == "foobar"
11
- Ciphr.transform('=ABBB b64',"").should be == "ABBB"
12
- Ciphr.transform('0x41',"").should be == "A"
13
- Ciphr.transform('0b01000001',"").should be == "A"
14
- Ciphr.transform('0x43 xor[0x01]',"").should be == "B"
15
- Ciphr.transform('0x4343 xor[0x01]',"").should be == "BB"
16
- Ciphr.transform('0x01 xor[0x4343]',"").should be == "BB"
17
- Ciphr.transform('0x00 url', "").should be == '%00'
18
- Ciphr.transform('"foo" cat', "").should be == 'foo'
19
- end
20
- end
21
- end
1
+ require 'spec_helper'
2
+ require 'ciphr'
3
+
4
+ describe Ciphr do
5
+ describe :transform do
6
+ it "works for some simple test cases" do
7
+ Ciphr.transform("md5 hex","").should be == "d41d8cd98f00b204e9800998ecf8427e"
8
+ Ciphr.transform("b64 ~b64","foobar").should be == "foobar"
9
+ Ciphr.transform("b2 b16 ~b16 ~b2","foobar").should be == "foobar"
10
+ Ciphr.transform('"foobar"',"").should be == "foobar"
11
+ Ciphr.transform('=ABBB b64',"").should be == "ABBB"
12
+ Ciphr.transform('0x41',"").should be == "A"
13
+ Ciphr.transform('0b01000001',"").should be == "A"
14
+ Ciphr.transform('0x43 xor[0x01]',"").should be == "B"
15
+ Ciphr.transform('0x4343 xor[0x01]',"").should be == "BB"
16
+ Ciphr.transform('0x01 xor[0x4343]',"").should be == "BB"
17
+ Ciphr.transform('0x00 url', "").should be == '%00'
18
+ Ciphr.transform('"foo" cat', "").should be == 'foo'
19
+ end
20
+ end
21
+ end
@@ -1,31 +1,31 @@
1
- require 'spec_helper'
2
- require 'ciphr'
3
-
4
- describe Ciphr::FunctionRegistry do
5
- describe :setup do
6
- it "sets up the specified functions" do
7
- Ciphr::FunctionRegistry.global.setup([Ciphr::Functions::Base::Base2, Ciphr::Functions::Simple::Cat])
8
- Ciphr::FunctionRegistry.global.functions.should ==
9
- [
10
- [Ciphr::Functions::Base::Base2, [[["b2", "base2", "bin", "binary"], {}]]],
11
- [Ciphr::Functions::Simple::Cat, [[["cat", "catenate"], {}]]]
12
- ]
13
- Ciphr::FunctionRegistry.global.function_aliases.should ==
14
- {
15
- "b2"=>[Ciphr::Functions::Base::Base2, {}],
16
- "base2"=>[Ciphr::Functions::Base::Base2, {}],
17
- "bin"=>[Ciphr::Functions::Base::Base2, {}],
18
- "binary"=>[Ciphr::Functions::Base::Base2, {}],
19
- "cat"=>[Ciphr::Functions::Simple::Cat, {}],
20
- "catenate"=>[Ciphr::Functions::Simple::Cat, {}]
21
- }
22
- end
23
- it "sets up the automatically registered functions" do
24
- Ciphr::FunctionRegistry.global.setup
25
- Ciphr::FunctionRegistry.global.functions.should include(
26
- [Ciphr::Functions::Base::Base2, [[["b2", "base2","bin","binary"], {}]]])
27
- Ciphr::FunctionRegistry.global.functions.should include(
28
- [Ciphr::Functions::Simple::Cat, [[["cat", "catenate"], {}]]])
29
- end
30
- end
31
- end
1
+ require 'spec_helper'
2
+ require 'ciphr'
3
+
4
+ describe Ciphr::FunctionRegistry do
5
+ describe :setup do
6
+ it "sets up the specified functions" do
7
+ Ciphr::FunctionRegistry.global.setup([Ciphr::Functions::Base::Base2, Ciphr::Functions::Simple::Cat])
8
+ Ciphr::FunctionRegistry.global.functions.should ==
9
+ [
10
+ [Ciphr::Functions::Base::Base2, [[["b2", "base2", "bin", "binary"], {}]]],
11
+ [Ciphr::Functions::Simple::Cat, [[["cat", "catenate"], {}]]]
12
+ ]
13
+ Ciphr::FunctionRegistry.global.function_aliases.should ==
14
+ {
15
+ "b2"=>[Ciphr::Functions::Base::Base2, {}],
16
+ "base2"=>[Ciphr::Functions::Base::Base2, {}],
17
+ "bin"=>[Ciphr::Functions::Base::Base2, {}],
18
+ "binary"=>[Ciphr::Functions::Base::Base2, {}],
19
+ "cat"=>[Ciphr::Functions::Simple::Cat, {}],
20
+ "catenate"=>[Ciphr::Functions::Simple::Cat, {}]
21
+ }
22
+ end
23
+ it "sets up the automatically registered functions" do
24
+ Ciphr::FunctionRegistry.global.setup
25
+ Ciphr::FunctionRegistry.global.functions.should include(
26
+ [Ciphr::Functions::Base::Base2, [[["b2", "base2","bin","binary"], {}]]])
27
+ Ciphr::FunctionRegistry.global.functions.should include(
28
+ [Ciphr::Functions::Simple::Cat, [[["cat", "catenate"], {}]]])
29
+ end
30
+ end
31
+ end
@@ -1,55 +1,55 @@
1
- require 'spec_helper'
2
- require 'ciphr'
3
-
4
- # considerations:
5
- # invertable
6
- # deterministic
7
- # padded
8
- # zero-input
9
-
10
- describe Ciphr::Functions do
11
- r = Random.new(0) #deterministic
12
- tests = [""] + (1..50).map do |i|
13
- mag = r.rand(4)+1
14
- len = r.rand(10**mag)
15
- #len = (0.00001*r.rand(100000)**1.7).floor
16
- #$stderr.puts len
17
- r.bytes(len)
18
- end
19
-
20
- # temporarily disable randomization
21
- tests = [""," ", "\x00", "\x00 A"]
22
-
23
- Ciphr::FunctionRegistry.global.setup
24
- #TODO: run shorter/smaller tests first
25
-
26
- #TODO: decompose property tests into small, composable tests
27
- functions = Ciphr::FunctionRegistry.global.functions
28
- functions.find_all{|f| f[0].params.size == 1}.each do |f|
29
- f[1].each do |v|
30
- tests.each do |t|
31
- it "#{v[0][0]} #{t.inspect}" do
32
- result = Ciphr.transform(v[0][0],t)
33
- if f[0] != Ciphr::Functions::Simple::Cat && t != ""
34
- expect(result).not_to eq(t)
35
- end
36
- if f[0].invertable? && t != ""
37
- inv = Ciphr.transform("~" + v[0][0],result)
38
- #FIXME: need to enforce consistent encoding
39
- inv,t = [inv,t].map{|s| s.force_encoding('binary')}
40
- case f[0].aligned # FIXME: this is horrible
41
- when :left
42
- expect(inv).to start_with(t)
43
- when :right
44
- expect(t).to end_with(inv) # FIXME: horribly backwards
45
- else
46
- expect(inv).to eq(t)
47
- end
48
- end
49
- end
50
- end
51
- end
52
- end
53
- end
54
-
55
-
1
+ require 'spec_helper'
2
+ require 'ciphr'
3
+
4
+ # considerations:
5
+ # invertable
6
+ # deterministic
7
+ # padded
8
+ # zero-input
9
+
10
+ describe Ciphr::Functions do
11
+ r = Random.new(0) #deterministic
12
+ tests = [""] + (1..50).map do |i|
13
+ mag = r.rand(4)+1
14
+ len = r.rand(10**mag)
15
+ #len = (0.00001*r.rand(100000)**1.7).floor
16
+ #$stderr.puts len
17
+ r.bytes(len)
18
+ end
19
+
20
+ # temporarily disable randomization
21
+ tests = [""," ", "\x00", "\x00 A"] + tests
22
+
23
+ Ciphr::FunctionRegistry.global.setup
24
+ #TODO: run shorter/smaller tests first
25
+
26
+ #TODO: decompose property tests into small, composable tests
27
+ functions = Ciphr::FunctionRegistry.global.functions
28
+ functions.find_all{|f| f[0].params.size == 1}.each do |f|
29
+ f[1].each do |v|
30
+ tests.each do |t|
31
+ it "#{v[0][0]} #{t.inspect}" do
32
+ result = Ciphr.transform(v[0][0],t)
33
+ if f[0] != Ciphr::Functions::Simple::Cat && f[0] != Ciphr::Functions::Ascii::Rot13 && t != ""
34
+ expect(result).not_to eq(t)
35
+ end
36
+ if f[0].invertable? && t != ""
37
+ inv = Ciphr.transform("~" + v[0][0],result)
38
+ #FIXME: need to enforce consistent encoding
39
+ inv,t = [inv,t].map{|s| s.force_encoding('binary')}
40
+ case f[0].aligned # FIXME: this is horrible
41
+ when :left
42
+ expect(inv).to start_with(t)
43
+ when :right
44
+ expect(t).to end_with(inv) # FIXME: horribly backwards
45
+ else
46
+ expect(inv).to eq(t)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+
@@ -1,4 +1,4 @@
1
- #require 'coveralls'
2
- #require "codeclimate-test-reporter"
3
- #Coveralls.wear!
4
- #CodeClimate::TestReporter.start
1
+ #require 'coveralls'
2
+ #require "codeclimate-test-reporter"
3
+ #Coveralls.wear!
4
+ #CodeClimate::TestReporter.start
@@ -1,38 +1,38 @@
1
- require 'spec_helper'
2
- require 'ciphr'
3
-
4
- describe Ciphr::Stream do
5
- describe :read do
6
- it "returns nil after proc does" do
7
- s = Ciphr::Stream.new Proc.new { nil }
8
- s.read(1).should be == nil
9
- end
10
-
11
- it "buffers and returns data as requested" do
12
- fills = ["abc", "def", "ghi"]
13
- s = Ciphr::Stream.new Proc.new { fills.shift }
14
- s.read(1).should be == "a"
15
- s.read(3).should be == "bcd"
16
- s.read(1).should be == "e"
17
- s.read(2).should be == "fg"
18
- s.read(4).should be == "hi"
19
- s.read(1).should be == nil
20
- end
21
-
22
- it "can prepend data and read it back out" do
23
- fills = ["abc", "def", "ghi"]
24
- s = Ciphr::Stream.new Proc.new { fills.shift }
25
- s.read(1).should be == "a"
26
- s.read(3).should be == "bcd"
27
- s.prepend("cd")
28
- s.read(1).should be == "c"
29
- s.read(1).should be == "d"
30
- s.read(1).should be == "e"
31
- s.prepend("cde")
32
- s.read(3).should be == "cde"
33
- s.read(2).should be == "fg"
34
- s.read(4).should be == "hi"
35
- s.read(1).should be == nil
36
- end
37
- end
38
- end
1
+ require 'spec_helper'
2
+ require 'ciphr'
3
+
4
+ describe Ciphr::Stream do
5
+ describe :read do
6
+ it "returns nil after proc does" do
7
+ s = Ciphr::Stream.new Proc.new { nil }
8
+ s.read(1).should be == nil
9
+ end
10
+
11
+ it "buffers and returns data as requested" do
12
+ fills = ["abc", "def", "ghi"]
13
+ s = Ciphr::Stream.new Proc.new { fills.shift }
14
+ s.read(1).should be == "a"
15
+ s.read(3).should be == "bcd"
16
+ s.read(1).should be == "e"
17
+ s.read(2).should be == "fg"
18
+ s.read(4).should be == "hi"
19
+ s.read(1).should be == nil
20
+ end
21
+
22
+ it "can prepend data and read it back out" do
23
+ fills = ["abc", "def", "ghi"]
24
+ s = Ciphr::Stream.new Proc.new { fills.shift }
25
+ s.read(1).should be == "a"
26
+ s.read(3).should be == "bcd"
27
+ s.prepend("cd")
28
+ s.read(1).should be == "c"
29
+ s.read(1).should be == "d"
30
+ s.read(1).should be == "e"
31
+ s.prepend("cde")
32
+ s.read(3).should be == "cde"
33
+ s.read(2).should be == "fg"
34
+ s.read(4).should be == "hi"
35
+ s.read(1).should be == nil
36
+ end
37
+ end
38
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ciphr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Frohoff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-12 00:00:00.000000000 Z
11
+ date: 2017-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,6 +122,7 @@ files:
122
122
  - lib/ciphr.rb
123
123
  - lib/ciphr/function_registry.rb
124
124
  - lib/ciphr/functions.rb
125
+ - lib/ciphr/functions/ascii.rb
125
126
  - lib/ciphr/functions/base_radix.rb
126
127
  - lib/ciphr/functions/bitwise.rb
127
128
  - lib/ciphr/functions/crypto.rb
@@ -133,8 +134,7 @@ files:
133
134
  - lib/ciphr/parser.rb
134
135
  - lib/ciphr/stream.rb
135
136
  - lib/ciphr/version.rb
136
- - pkg/ciphr-0.0.1.gem
137
- - pkg/ciphr-0.0.2.gem
137
+ - pkg/ciphr-0.0.3.gem
138
138
  - spec/ciphr_spec.rb
139
139
  - spec/functions_spec.rb
140
140
  - spec/randomizer_spec.rb
@@ -170,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
170
  version: '0'
171
171
  requirements: []
172
172
  rubyforge_project:
173
- rubygems_version: 2.4.8
173
+ rubygems_version: 2.5.2
174
174
  signing_key:
175
175
  specification_version: 4
176
176
  summary: a CLI tool for performing and composing encoding, decoding, encryption, decryption,
@@ -182,4 +182,3 @@ test_files:
182
182
  - spec/randomizer_spec.rb
183
183
  - spec/spec_helper.rb
184
184
  - spec/stream_spec.rb
185
- has_rdoc: