symmetric-encryption 0.6.1 → 0.7.0
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.
- data/csv.zip +0 -0
- data/csv_encrypted +0 -0
- data/csv_encrypted_zip +0 -0
- data/lib/symmetric_encryption/reader.rb +44 -0
- data/lib/symmetric_encryption/version.rb +1 -1
- data/lib/symmetric_encryption/writer.rb +2 -2
- data/test/reader_test.rb +3 -4
- data/test/writer_test.rb +2 -2
- metadata +6 -5
- data/symmetric-encryption-0.6.0.gem +0 -0
data/csv.zip
ADDED
Binary file
|
data/csv_encrypted
ADDED
Binary file
|
data/csv_encrypted_zip
ADDED
Binary file
|
@@ -223,6 +223,50 @@ module SymmetricEncryption
|
|
223
223
|
read_header
|
224
224
|
end
|
225
225
|
|
226
|
+
# Seeks to a given offset (Integer) in the stream according to the value of whence:
|
227
|
+
# IO::SEEK_CUR | Seeks to _amount_ plus current position
|
228
|
+
# --------------+----------------------------------------------------
|
229
|
+
# IO::SEEK_END | Seeks to _amount_ plus end of stream (you probably
|
230
|
+
# | want a negative value for _amount_)
|
231
|
+
# --------------+----------------------------------------------------
|
232
|
+
# IO::SEEK_SET | Seeks to the absolute location given by _amount_
|
233
|
+
#
|
234
|
+
# WARNING: IO::SEEK_SET will jump to the beginning of the file and
|
235
|
+
# then re-read upto the point specified
|
236
|
+
# WARNING: IO::SEEK_END will read the entire file and then again
|
237
|
+
# upto the point specified
|
238
|
+
def seek(amount, whence=IO::SEEK_SET)
|
239
|
+
offset = 0
|
240
|
+
case whence
|
241
|
+
when IO::SEEK_SET
|
242
|
+
offset = amount
|
243
|
+
rewind
|
244
|
+
when IO::SEEK_CUR
|
245
|
+
if amount >= 0
|
246
|
+
offset = amount
|
247
|
+
else
|
248
|
+
offset = @pos + amount
|
249
|
+
rewind
|
250
|
+
end
|
251
|
+
when IO::SEEK_END
|
252
|
+
rewind
|
253
|
+
# Read and decrypt entire file a block at a time to get its total
|
254
|
+
# unencrypted size
|
255
|
+
size = 0
|
256
|
+
while !eof
|
257
|
+
read_block
|
258
|
+
size += @read_buffer.size
|
259
|
+
@read_buffer = ''
|
260
|
+
end
|
261
|
+
rewind
|
262
|
+
offset = size + amount
|
263
|
+
else
|
264
|
+
raise "unknown whence:#{whence} supplied to seek()"
|
265
|
+
end
|
266
|
+
read(offset) if offset > 0
|
267
|
+
0
|
268
|
+
end
|
269
|
+
|
226
270
|
private
|
227
271
|
|
228
272
|
# Read the header from the file if present
|
@@ -29,7 +29,7 @@ module SymmetricEncryption
|
|
29
29
|
# The header contains:
|
30
30
|
# Version of the encryption key used to encrypt the file
|
31
31
|
# Indicator if the data was compressed
|
32
|
-
# Default:
|
32
|
+
# Default: true
|
33
33
|
#
|
34
34
|
# :version
|
35
35
|
# Version of the encryption key to use when encrypting
|
@@ -82,7 +82,7 @@ module SymmetricEncryption
|
|
82
82
|
# Encrypt data before writing to the supplied stream
|
83
83
|
def initialize(ios,options={})
|
84
84
|
@ios = ios
|
85
|
-
header = options.fetch(:header,
|
85
|
+
header = options.fetch(:header, true)
|
86
86
|
# Compress is only used at this point for setting the flag in the header
|
87
87
|
@compress = options.fetch(:compress, false)
|
88
88
|
|
data/test/reader_test.rb
CHANGED
@@ -69,13 +69,12 @@ class ReaderTest < Test::Unit::TestCase
|
|
69
69
|
|
70
70
|
context "reading from file" do
|
71
71
|
# With and without header
|
72
|
-
[false, true].each do |
|
73
|
-
context "with#{'out' unless header} header" do
|
72
|
+
[{:header => false}, {:header => true}, {:header => true, :compress => true}].each do |options|
|
73
|
+
context "with#{'out' unless options[:header]} header" do
|
74
74
|
setup do
|
75
75
|
@filename = '._test'
|
76
|
-
@options = { :header => header }
|
77
76
|
# Create encrypted file
|
78
|
-
SymmetricEncryption::Writer.open(@filename,
|
77
|
+
SymmetricEncryption::Writer.open(@filename, options) do |file|
|
79
78
|
@data.inject(0) {|sum,str| sum + file.write(str)}
|
80
79
|
end
|
81
80
|
end
|
data/test/writer_test.rb
CHANGED
@@ -31,7 +31,7 @@ class EncryptionWriterTest < Test::Unit::TestCase
|
|
31
31
|
|
32
32
|
should "encrypt to string stream" do
|
33
33
|
stream = StringIO.new
|
34
|
-
file = SymmetricEncryption::Writer.new(stream)
|
34
|
+
file = SymmetricEncryption::Writer.new(stream, :header => false)
|
35
35
|
written_len = @data.inject(0) {|sum,str| sum + file.write(str)}
|
36
36
|
file.close
|
37
37
|
|
@@ -50,7 +50,7 @@ class EncryptionWriterTest < Test::Unit::TestCase
|
|
50
50
|
|
51
51
|
should "encrypt to file using .open" do
|
52
52
|
written_len = nil
|
53
|
-
SymmetricEncryption::Writer.open(@filename) do |file|
|
53
|
+
SymmetricEncryption::Writer.open(@filename, :header => false) do |file|
|
54
54
|
written_len = @data.inject(0) {|sum,str| sum + file.write(str)}
|
55
55
|
end
|
56
56
|
assert_equal @data_len, written_len
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 7
|
8
|
+
- 0
|
9
|
+
version: 0.7.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Reid Morrison
|
@@ -28,6 +28,9 @@ extensions: []
|
|
28
28
|
extra_rdoc_files: []
|
29
29
|
|
30
30
|
files:
|
31
|
+
- csv.zip
|
32
|
+
- csv_encrypted
|
33
|
+
- csv_encrypted_zip
|
31
34
|
- examples/symmetric-encryption.yml
|
32
35
|
- lib/csv_encrypted
|
33
36
|
- lib/symmetric-encryption.rb
|
@@ -50,8 +53,6 @@ files:
|
|
50
53
|
- nbproject/project.xml
|
51
54
|
- Rakefile
|
52
55
|
- README.md
|
53
|
-
- symmetric-encryption-0.6.0.gem
|
54
|
-
- symmetric-encryption-0.6.1.gem
|
55
56
|
- test/attr_encrypted_test.rb
|
56
57
|
- test/cipher_test.rb
|
57
58
|
- test/config/database.yml
|
Binary file
|