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 +4 -4
- data/lib/crypto-toolbox/crypt_buffer.rb +15 -8
- data/lib/crypto-toolbox/crypt_buffer/concerns/array.rb +26 -0
- data/lib/crypto-toolbox/crypt_buffer/concerns/convertable.rb +15 -0
- data/lib/crypto-toolbox/crypt_buffer/concerns/random.rb +1 -1
- data/lib/crypto-toolbox/crypt_buffer/concerns/xor.rb +4 -4
- data/lib/crypto-toolbox/crypt_buffer_input_converter.rb +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df8683094fec6537792c932072ef5cbf704e9229
|
4
|
+
data.tar.gz: 675704384e2a84542f6dfba77a44dbdc09a52491
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
+
|
@@ -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
|
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
|
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.
|
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-
|
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
|