crypto-toolbox 0.1.14 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5728516f47174d06b0901a72afa8a499ee5f0662
4
- data.tar.gz: 9d83b1da078d82ba3345fb4b8aca1f860aaf1eb5
3
+ metadata.gz: df8683094fec6537792c932072ef5cbf704e9229
4
+ data.tar.gz: 675704384e2a84542f6dfba77a44dbdc09a52491
5
5
  SHA512:
6
- metadata.gz: 21c9a10d814988c289b578850e1b769c817e086cd47a369578a01bdd8f5058ea6e1ef0573d311ab4ee6b3ee54f038ddc043475af83ae8f8a5112c02e126351af
7
- data.tar.gz: 81601d2d3376c364ef5437b6d5af7c33bd4b3e47658eda3fa68a220439f4a6580fe0e20b3a6030909b9a52c89ad2e8026cb383dd7d2a7f6ebbd1eea84ee521c1
6
+ metadata.gz: 1a1a771fdfeecf30f4db5db4c814d609c98ce779fe823d37e59f1c48cb026d846affa615042128ad53ff8393eb48fc78d3fb17d703a8f8eeb290c60f89a53497
7
+ data.tar.gz: 3a5c2d78c13dac462077713ea4142a1a7bf280ea24e1b2ffc986ba1de190e0e6fd849b031069858d9316836ad990504db17999a74186ebc5a49178bb132622d2
@@ -2,7 +2,9 @@ require 'aes'
2
2
  require 'openssl'
3
3
  require 'forwardable'
4
4
 
5
+
5
6
  require 'crypto-toolbox/crypt_buffer/concerns/arithmetic.rb'
7
+ require 'crypto-toolbox/crypt_buffer/concerns/array.rb'
6
8
  require 'crypto-toolbox/crypt_buffer/concerns/byte_expander.rb'
7
9
  require 'crypto-toolbox/crypt_buffer/concerns/comparable.rb'
8
10
  require 'crypto-toolbox/crypt_buffer/concerns/convertable.rb'
@@ -13,8 +15,21 @@ require 'crypto-toolbox/crypt_buffer/concerns/xor.rb'
13
15
 
14
16
  class CryptBuffer
15
17
  class OutOfRangeError < RuntimeError; end
18
+ attr_accessor :bytes
19
+ alias_method :b, :bytes
20
+
16
21
 
22
+ include Enumerable
23
+ extend Forwardable
24
+ def_delegators :@bytes,:empty?,:include?, :length, :each, :^, :|, :&
25
+
26
+ # NOTE
27
+ # we need to include all the extensions after the regular delegate
28
+ # otherwise we are not able to overwrite methods like first/last
29
+ # which would result in the inability of casting the result to a
30
+ # new cryptbuffer instance, thus leaving the return value an array
17
31
  include CryptBufferConcern::Arithmetic
32
+ include CryptBufferConcern::Array
18
33
  include CryptBufferConcern::ByteExpander
19
34
  include CryptBufferConcern::Convertable
20
35
  include CryptBufferConcern::Comparable
@@ -23,14 +38,6 @@ class CryptBuffer
23
38
  include CryptBufferConcern::Random
24
39
  include CryptBufferConcern::Xor
25
40
 
26
-
27
- include Enumerable
28
- extend Forwardable
29
- def_delegators :@bytes, :[], :empty?,:include?, :each, :length
30
-
31
-
32
- attr_accessor :bytes
33
- alias_method :b, :bytes
34
41
 
35
42
 
36
43
  def initialize(byte_array)
@@ -0,0 +1,26 @@
1
+ module CryptBufferConcern
2
+ module Array
3
+ def +(other)
4
+ # make sure the input is a cryptbuffer
5
+ # Thus we support cryptbuffers and byte arrays
6
+ CryptBuffer(bytes + CryptBuffer(other).bytes)
7
+ end
8
+
9
+ def shift(n = 1)
10
+ CryptBuffer(bytes.shift(n))
11
+ end
12
+
13
+ def first(n = 1 )
14
+ CryptBuffer(bytes.first(n))
15
+ end
16
+
17
+ def last(n = 1)
18
+ CryptBuffer(bytes.last(n))
19
+ end
20
+
21
+ def [](anything)
22
+ CryptBuffer(bytes[anything])
23
+ end
24
+
25
+ end
26
+ end
@@ -29,3 +29,18 @@ module CryptBufferConcern
29
29
  end
30
30
  end
31
31
  end
32
+
33
+ module CryptBufferConcern
34
+ module TypeExtension
35
+ def to_crypt_buffer
36
+ CryptBuffer(self)
37
+ end
38
+ end
39
+ end
40
+
41
+ String.send(:include, CryptBufferConcern::TypeExtension)
42
+ Fixnum.send(:include, CryptBufferConcern::TypeExtension)
43
+ Array.send(:include, CryptBufferConcern::TypeExtension)
44
+
45
+
46
+
@@ -20,7 +20,7 @@ module CryptBufferConcern
20
20
  def generate_bytes(n,seed)
21
21
  prg = ::Random.new(seed)
22
22
 
23
- Array.new(n.to_i) { prg.rand 256 }
23
+ ::Array.new(n.to_i) { prg.rand 256 }
24
24
  end
25
25
  end
26
26
 
@@ -2,12 +2,12 @@ module CryptBufferConcern
2
2
  module Xor
3
3
  def xor_at(input,pos)
4
4
  return self if input.nil? || (pos.abs > length)
5
-
6
- case input
7
- when Array
5
+
6
+ case input.respond_to?(:to_ary)
7
+ when true
8
8
  # map our current data to xor all inputs with the given bytepos.
9
9
  # all other bytes are kept as they were
10
- tmp = bytes.map.with_index{|b,i| i == pos ? xor_multiple(b,input) : b }
10
+ tmp = bytes.map.with_index{|b,i| i == pos ? xor_multiple(b,input.to_ary) : b }
11
11
  CryptBuffer(tmp)
12
12
  else
13
13
  tmp = bytes
@@ -27,6 +27,8 @@ class CryptBufferInputConverter
27
27
  input.b
28
28
  when Fixnum
29
29
  int2bytes(input)
30
+ when NilClass
31
+ []
30
32
  else
31
33
  raise "Unsupported input: #{input.inspect} of class #{input.class}"
32
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crypto-toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Sivia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-26 00:00:00.000000000 Z
11
+ date: 2015-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aes
@@ -65,6 +65,7 @@ files:
65
65
  - lib/crypto-toolbox/ciphers/rot13.rb
66
66
  - lib/crypto-toolbox/crypt_buffer.rb
67
67
  - lib/crypto-toolbox/crypt_buffer/concerns/arithmetic.rb
68
+ - lib/crypto-toolbox/crypt_buffer/concerns/array.rb
68
69
  - lib/crypto-toolbox/crypt_buffer/concerns/byte_expander.rb
69
70
  - lib/crypto-toolbox/crypt_buffer/concerns/comparable.rb
70
71
  - lib/crypto-toolbox/crypt_buffer/concerns/convertable.rb