crypto-toolbox 0.0.14 → 0.0.15
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 +4 -4
- data/lib/crypto-toolbox/crypt_buffer.rb +24 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aaa50aacf7378e640bcb5ea072b67d93c90464df
|
4
|
+
data.tar.gz: 96847ad9ca8cf81d07eb1825fdca0b60f9b9616d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89f27cad16d13384efe865e5ec220aa1b7d425f6a5afd8bdafb1ae122bcedb8f7d022f752a3ec9f69b4c2d043dc41923cdd515bd892641a05b1c3671d8a3f87e
|
7
|
+
data.tar.gz: aaee5b18609b52dc810241ac37551b8c8c0e4cc57f321344668c6aed733051843bc6867b9e5868fda9bd0668e46a4417cd5e4ef79f9cd24b35881f62736c3b1c
|
@@ -3,12 +3,13 @@ require 'openssl'
|
|
3
3
|
|
4
4
|
class CryptBuffer
|
5
5
|
class OutOfRangeError < RuntimeError; end
|
6
|
-
|
7
6
|
|
8
7
|
attr_accessor :bytes
|
9
8
|
|
10
9
|
include Enumerable
|
11
|
-
|
10
|
+
extend Forwardable
|
11
|
+
def_delegators :@bytes, :[], :empty?,:include?, :length
|
12
|
+
|
12
13
|
def initialize(input)
|
13
14
|
@bytes = bytes_from_any(input)
|
14
15
|
end
|
@@ -83,6 +84,24 @@ class CryptBuffer
|
|
83
84
|
end
|
84
85
|
CryptBuffer(tmp)
|
85
86
|
end
|
87
|
+
|
88
|
+
|
89
|
+
def xor_at(input,pos)
|
90
|
+
return self if input.nil? || (pos.abs > length)
|
91
|
+
|
92
|
+
case input
|
93
|
+
when Array
|
94
|
+
# map our current data to xor all inputs with the given bytepos.
|
95
|
+
# all other bytes are kept as they were
|
96
|
+
tmp = bytes.map.with_index{|b,i| i == pos ? xor_multiple(b,input) : b }
|
97
|
+
CryptBuffer(tmp)
|
98
|
+
else
|
99
|
+
tmp = bytes
|
100
|
+
tmp[pos] = tmp[pos] ^ input
|
101
|
+
CryptBuffer(tmp)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
86
105
|
def xor(input,expand_input: false)
|
87
106
|
if expand_input
|
88
107
|
xor_all_with(input)
|
@@ -127,6 +146,9 @@ class CryptBuffer
|
|
127
146
|
(input * n) + input[0,rest]
|
128
147
|
end
|
129
148
|
end
|
149
|
+
def xor_multiple(byte,bytes)
|
150
|
+
([byte] + bytes).reduce(:^)
|
151
|
+
end
|
130
152
|
def bytes_from_any(input)
|
131
153
|
case input
|
132
154
|
when Array
|