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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 855fa68c984b157e774117b3cd5806d11afdc0ba
4
- data.tar.gz: 8a4fd65dceaa6d7490e8f9865da8cdc5cddfa2b6
3
+ metadata.gz: aaa50aacf7378e640bcb5ea072b67d93c90464df
4
+ data.tar.gz: 96847ad9ca8cf81d07eb1825fdca0b60f9b9616d
5
5
  SHA512:
6
- metadata.gz: b415280b51fc55662ae73195f271d0547b7ad49a065f5f5a4e1172ec6ec8af34875bbbf493673e15e359ebf9e9bd677e923060fede837839c1ada96d61ae13bd
7
- data.tar.gz: 3c166e9f450962718f61be0a2daac7d0fd647a426ce7ea4dee8cddcfe08b0f8b8ea8a396ccb8e290f22b835e8bbe0a82f80701a82f3c03f82250a4f69b5fcae3
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crypto-toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Sivia