sym-crypt 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +17 -20
- data/README.md +2 -3
- data/lib/sym/configurable.rb +13 -28
- data/lib/sym/crypt.rb +6 -10
- data/lib/sym/crypt/configuration.rb +15 -18
- data/lib/sym/crypt/extensions/instance_methods.rb +2 -2
- data/lib/sym/crypt/version.rb +3 -3
- data/lib/sym/data.rb +22 -0
- data/lib/sym/data/decoder.rb +29 -0
- data/lib/sym/data/encoder.rb +23 -0
- data/lib/sym/data/wrapper_struct.rb +42 -0
- data/sym-crypt.gemspec +0 -7
- metadata +7 -36
- data/lib/sym/crypt/data.rb +0 -24
- data/lib/sym/crypt/data/decoder.rb +0 -31
- data/lib/sym/crypt/data/encoder.rb +0 -25
- data/lib/sym/crypt/data/wrapper_struct.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7dc2ade67af9119488543dc9a44f57f0eb5aec124ac6c1bee63e2aabdda4d8b9
|
4
|
+
data.tar.gz: cd42ea8448dbb8289bfc55e5ac8858a11ad68b552f75c82d2c87daad3080033b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 271491ac5d56ac35fa96aa50d5b991e3890ec82d1fbe4708bd50ce4a543d694d7155bf5d73a8f1bc8e9db0e61ec5ab250615160b9444b2e1151d60539ac9c353
|
7
|
+
data.tar.gz: 9c6be8f7d8ed87c41b8bc70d678ba93781ce3e7f7c32a803524b9a13a6b5fc29d7222712bd38e643e86a5a5f4fa2f50eba05dc40d12efa70c1e33f607f799766
|
data/.travis.yml
CHANGED
@@ -1,23 +1,20 @@
|
|
1
1
|
language: ruby
|
2
2
|
cache: bundler
|
3
|
-
env:
|
4
|
-
CODECLIMATE_REPO_TOKEN=40b229d2d4857d67d832b6e0d5110537accb4e954961a8ce59beebf41e7d79b7
|
5
3
|
rvm:
|
6
|
-
- 2.2.
|
7
|
-
- 2.3.
|
8
|
-
- 2.4.
|
9
|
-
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
- bundle exec codeclimate-test-reporter
|
4
|
+
- 2.2.10
|
5
|
+
- 2.3.8
|
6
|
+
- 2.4.6
|
7
|
+
- 2.5.5
|
8
|
+
- 2.6.2
|
9
|
+
- jruby-9.2.5.0
|
10
|
+
- jruby-9.2.6.0
|
11
|
+
env:
|
12
|
+
global:
|
13
|
+
secure: MLkFJDFyxLetmt934cEHRq5u1RMJSZ+SOsSEYq8RtXTW+UjuiWndDn27rKEXRZq8njYKROIZHXtYPZqz7vxFe6oA7zar4cFh9c2/T8N7gp9ekeaSYN3yBP+HzzO0RQeZu69J2VWW0VOua9xrr1e4M1foiRUXeu4+bjqhZQH83TBEahTLnhe3x5UBMVnAAOVPC0R19zVHTESmKCpkFTk+kMCOD4K5BJ3R2NVfAY9KmPqRPh5/jFDkaeOYiMVal466gh/16rK9WbzarqODgJD3Xi32A68K7nbMmGAEbsltQuIxSwrOvP/xmjoikdM9uxxsqSpP+qlfWZL8TUn1EJwRmvXajCE9ak59SAiaieOqfKScouoSajNcTafHdD97y8iFCXqx2b4/QYCrG2RSn8obe0pmHTNQl4mYyGhcnDrmjku+8oGJT007K3Xv5zW6Mm78l2g5HjrbqeDmAQpz1RI6iZyEhOI5ujdv3+jBdIv6KWEaFD1mskHciGB0y0C2YzNa4gSkR5d81tsrsFhbefaq86s11MuDV71YNvTLiy4s3CMeqBSGbZFgEb6LNUsoTbXkRCejdigeg3ZXUpb372tEQhQEHnV7mE4JkXixav6Simfg39N1DPpP4GOpegvIL2SdN7cXpnBEbZ5WILi4ghpf0BnyOTdRjwyMigNCzgtY6NA=
|
14
|
+
before_script:
|
15
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
16
|
+
- chmod +x ./cc-test-reporter
|
17
|
+
- ./cc-test-reporter before-build
|
18
|
+
script: bundle exec rspec
|
19
|
+
after_script:
|
20
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/README.md
CHANGED
@@ -6,9 +6,8 @@
|
|
6
6
|
[![Downloads](http://ruby-gem-downloads-badge.herokuapp.com/sym-crypt?type=total)](https://rubygems.org/gems/sym-crypt)
|
7
7
|
|
8
8
|
[![Build Status](https://travis-ci.org/kigster/sym-crypt.svg?branch=master)](https://travis-ci.org/kigster/sym-crypt)
|
9
|
-
[![
|
10
|
-
[![Test Coverage](https://codeclimate.com/
|
11
|
-
[![Issue Count](https://codeclimate.com/github/kigster/sym-crypt/badges/issue_count.svg)](https://codeclimate.com/github/kigster/sym-crypt)
|
9
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/3215796bda088851bfb7/maintainability)](https://codeclimate.com/github/kigster/sym-crypt/maintainability)
|
10
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/3215796bda088851bfb7/test_coverage)](https://codeclimate.com/github/kigster/sym-crypt/test_coverage)
|
12
11
|
|
13
12
|
[![Gitter](https://img.shields.io/gitter/room/gitterHQ/gitter.svg)](https://gitter.im/kigster/sym)
|
14
13
|
|
data/lib/sym/configurable.rb
CHANGED
@@ -4,40 +4,25 @@ module Sym
|
|
4
4
|
def self.included(base)
|
5
5
|
base.instance_eval do
|
6
6
|
include Singleton
|
7
|
-
class << self
|
8
|
-
include Sym::Configurable::ClassMethods
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
7
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
8
|
+
class << self
|
9
|
+
def config
|
10
|
+
instance
|
11
|
+
end
|
17
12
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
13
|
+
def configure
|
14
|
+
yield config if block_given?
|
15
|
+
config
|
16
|
+
end
|
22
17
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
if klazz.const_defined?(:DEFAULTS)
|
27
|
-
default_proc = self.const_get(:DEFAULTS)
|
28
|
-
if default_proc.respond_to?(:call)
|
29
|
-
configure(&default_proc)
|
30
|
-
end
|
18
|
+
def property(prop_name, prop_value = nil)
|
19
|
+
config.send("#{prop_name}=", prop_value) if prop_name && prop_value
|
20
|
+
config.send(prop_name)
|
31
21
|
end
|
32
|
-
end
|
33
|
-
end
|
34
22
|
|
35
|
-
|
36
|
-
|
23
|
+
alias_method :[], :property
|
24
|
+
end
|
37
25
|
end
|
38
|
-
|
39
|
-
alias_method :prop, :property
|
40
|
-
alias_method :[], :property
|
41
26
|
end
|
42
27
|
end
|
43
28
|
end
|
data/lib/sym/crypt.rb
CHANGED
@@ -6,8 +6,6 @@ require 'sym/crypt/errors'
|
|
6
6
|
|
7
7
|
require 'sym/crypt/configuration'
|
8
8
|
|
9
|
-
Sym::Crypt::Configuration.defaults!
|
10
|
-
|
11
9
|
require 'sym/crypt/extensions/class_methods'
|
12
10
|
require 'sym/crypt/extensions/instance_methods'
|
13
11
|
|
@@ -73,16 +71,18 @@ module Sym
|
|
73
71
|
|
74
72
|
def self.included(klass)
|
75
73
|
klass.instance_eval do
|
74
|
+
|
76
75
|
include ::Sym::Crypt::Extensions::InstanceMethods
|
77
76
|
extend ::Sym::Crypt::Extensions::ClassMethods
|
77
|
+
|
78
78
|
class << self
|
79
79
|
def private_key(value = nil)
|
80
80
|
if value
|
81
|
-
@private_key= value
|
81
|
+
@private_key = value
|
82
82
|
elsif @private_key
|
83
83
|
@private_key
|
84
84
|
else
|
85
|
-
@private_key= self.create_private_key
|
85
|
+
@private_key = self.create_private_key
|
86
86
|
end
|
87
87
|
@private_key
|
88
88
|
end
|
@@ -99,12 +99,8 @@ module Sym
|
|
99
99
|
end
|
100
100
|
|
101
101
|
Sym::Crypt::Configuration.configure do |config|
|
102
|
-
config.password_cipher
|
103
|
-
|
104
|
-
config.data_cipher = 'AES-256-CBC'
|
105
|
-
config.private_key_cipher = config.data_cipher
|
106
|
-
config.compression_enabled = true
|
107
|
-
config.compression_level = Zlib::BEST_COMPRESSION
|
102
|
+
# config.password_cipher = 'AES-128-CBC'
|
103
|
+
# etc...
|
108
104
|
end
|
109
105
|
|
110
106
|
class Object
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'singleton'
|
2
2
|
require 'sym/configurable'
|
3
|
+
require 'sym/crypt/configuration'
|
3
4
|
require 'ostruct'
|
4
5
|
module Sym
|
5
6
|
module Crypt
|
@@ -24,27 +25,23 @@ module Sym
|
|
24
25
|
# config.compression_level = Zlib::BEST_COMPRESSION
|
25
26
|
# end
|
26
27
|
|
27
|
-
class Configuration
|
28
|
+
class Configuration
|
29
|
+
attr_accessor :password_cipher,
|
30
|
+
:data_cipher,
|
31
|
+
:private_key_cipher,
|
32
|
+
:compression_enabled,
|
33
|
+
:compression_level
|
28
34
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
+
def initialize
|
36
|
+
self.password_cipher = 'AES-128-CBC'
|
37
|
+
self.data_cipher = 'AES-256-CBC'
|
38
|
+
self.private_key_cipher = data_cipher
|
39
|
+
self.compression_enabled = true
|
40
|
+
self.compression_level = Zlib::BEST_COMPRESSION
|
41
|
+
end
|
35
42
|
|
36
|
-
|
43
|
+
include Sym::Configurable
|
37
44
|
|
38
|
-
def default_proc
|
39
|
-
->(config) do
|
40
|
-
config.password_cipher = 'AES-128-CBC'
|
41
|
-
config.data_cipher = 'AES-256-CBC'
|
42
|
-
config.private_key_cipher = config.data_cipher
|
43
|
-
config.compression_enabled = true
|
44
|
-
config.compression_level = Zlib::BEST_COMPRESSION
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
45
|
end
|
49
46
|
end
|
50
47
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'sym/crypt'
|
2
|
-
require 'sym/
|
2
|
+
require 'sym/data'
|
3
3
|
require 'sym/crypt/cipher_handler'
|
4
4
|
require 'openssl'
|
5
5
|
module Sym
|
@@ -17,7 +17,7 @@ module Sym
|
|
17
17
|
# of various ciphers, by calling into the private +_encr+ and +_decr+
|
18
18
|
# methods.f
|
19
19
|
module InstanceMethods
|
20
|
-
include Sym::
|
20
|
+
include Sym::Data
|
21
21
|
include Sym::Crypt::CipherHandler
|
22
22
|
|
23
23
|
# Expects key to be a base64 encoded key
|
data/lib/sym/crypt/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Sym
|
2
2
|
module Crypt
|
3
|
-
|
4
|
-
|
3
|
+
VERSION = '1.2.0'
|
4
|
+
DESCRIPTION = <<-eof
|
5
5
|
sym-crypt is a core encryption module for the symmetric encryption app
|
6
6
|
(and a corresponding gem) "sym", and contains the main base serialization,
|
7
7
|
encryption, encoding, compression routines.
|
@@ -12,6 +12,6 @@ password sym-crypt uses AES-128-CBC cipher.
|
|
12
12
|
|
13
13
|
The resulting data is zlib-compressed and base64-encoded. The keys are also
|
14
14
|
base64 encoded for easy copying/pasting/etc.
|
15
|
-
|
15
|
+
eof
|
16
16
|
end
|
17
17
|
end
|
data/lib/sym/data.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'zlib'
|
3
|
+
|
4
|
+
require 'sym/data/encoder'
|
5
|
+
require 'sym/data/decoder'
|
6
|
+
require 'sym/data/wrapper_struct'
|
7
|
+
|
8
|
+
module Sym
|
9
|
+
# This module is responsible for taking arbitrary data of any format, and safely compressing
|
10
|
+
# the result of `Marshal.dump(data)` using Zlib, and then doing `#urlsafe_encode64` encoding
|
11
|
+
# to convert it to a string,
|
12
|
+
module Data
|
13
|
+
def encode(data, compress = true)
|
14
|
+
Encoder.new(data, compress).data_encoded
|
15
|
+
end
|
16
|
+
|
17
|
+
def decode(data_encoded, compress = nil)
|
18
|
+
Decoder.new(data_encoded, compress).data
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'sym/crypt/errors'
|
2
|
+
require 'base64'
|
3
|
+
require 'zlib'
|
4
|
+
|
5
|
+
module Sym
|
6
|
+
module Data
|
7
|
+
class Decoder
|
8
|
+
attr_accessor :data, :data_encoded, :data
|
9
|
+
|
10
|
+
def initialize(data_encoded, compress)
|
11
|
+
self.data_encoded = data_encoded
|
12
|
+
self.data = begin
|
13
|
+
Base64.urlsafe_decode64(data_encoded)
|
14
|
+
rescue
|
15
|
+
data_encoded
|
16
|
+
end
|
17
|
+
|
18
|
+
if compress.nil? || compress # auto-guess
|
19
|
+
self.data = begin
|
20
|
+
Zlib::Inflate.inflate(data)
|
21
|
+
rescue Zlib::Error => e
|
22
|
+
data
|
23
|
+
end
|
24
|
+
end
|
25
|
+
self.data = Marshal.load(data)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'zlib'
|
3
|
+
|
4
|
+
require 'sym/crypt/configuration'
|
5
|
+
|
6
|
+
module Sym
|
7
|
+
module Data
|
8
|
+
class Encoder
|
9
|
+
attr_accessor :data, :data_encoded
|
10
|
+
|
11
|
+
def initialize(data, compress)
|
12
|
+
self.data = data
|
13
|
+
self.data_encoded = Marshal.dump(data)
|
14
|
+
self.data_encoded = Zlib::Deflate.deflate(data_encoded, compression_level) if compress
|
15
|
+
self.data_encoded = Base64.urlsafe_encode64(data_encoded)
|
16
|
+
end
|
17
|
+
|
18
|
+
def compression_level
|
19
|
+
Sym::Crypt::Configuration.config.compression_level
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Sym
|
2
|
+
module Data
|
3
|
+
class WrapperStruct < Struct.new(
|
4
|
+
:encrypted_data, # [Blob] Binary encrypted data (possibly compressed)
|
5
|
+
:iv, # [String] IV used to encrypt the data
|
6
|
+
:cipher_name, # [String] Name of the cipher used
|
7
|
+
:salt, # [Integer] For password-encrypted data this is the salt
|
8
|
+
:version, # [Integer] Version of the cipher used
|
9
|
+
:compress # [Boolean] indicates if compression should be applied
|
10
|
+
)
|
11
|
+
|
12
|
+
VERSION = 1
|
13
|
+
|
14
|
+
attr_accessor :compressed
|
15
|
+
|
16
|
+
def initialize(
|
17
|
+
encrypted_data:, # [Blob] Binary encrypted data (possibly compressed)
|
18
|
+
iv:, # [String] IV used to encrypt the data
|
19
|
+
cipher_name:, # [String] Name of the cipher used
|
20
|
+
salt: nil, # [Integer] For password-encrypted data this is the salt
|
21
|
+
version: VERSION, # [Integer] Version of the cipher used
|
22
|
+
compress: Sym::Crypt::Configuration.config.compression_enabled
|
23
|
+
)
|
24
|
+
super(encrypted_data, iv, cipher_name, salt, version, compress)
|
25
|
+
end
|
26
|
+
|
27
|
+
def config
|
28
|
+
Sym::Crypt::Configuration.config
|
29
|
+
end
|
30
|
+
|
31
|
+
def serialize
|
32
|
+
Marshal.dump(self)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.deserialize(data)
|
36
|
+
Marshal.load(data)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
data/sym-crypt.gemspec
CHANGED
@@ -21,16 +21,9 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.require_paths = ['lib']
|
22
22
|
spec.required_ruby_version = '>= 2.2'
|
23
23
|
|
24
|
-
#spec.add_dependency 'activesupport'
|
25
|
-
#spec.add_dependency 'highline', '~> 1.7'
|
26
|
-
#spec.add_dependency 'coin', '~> 0.1.8'
|
27
|
-
#spec.add_dependency 'dalli', '~> 2.7'
|
28
|
-
|
29
|
-
spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
|
30
24
|
spec.add_development_dependency 'simplecov'
|
31
25
|
spec.add_development_dependency 'colored2'
|
32
26
|
spec.add_development_dependency 'irbtools'
|
33
|
-
spec.add_development_dependency 'bundler', '~> 1'
|
34
27
|
spec.add_development_dependency 'rake'
|
35
28
|
spec.add_development_dependency 'rspec', '~> 3'
|
36
29
|
spec.add_development_dependency 'rspec-its'
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sym-crypt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Gredeskoul
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: codeclimate-test-reporter
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: simplecov
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,20 +52,6 @@ dependencies:
|
|
66
52
|
- - ">="
|
67
53
|
- !ruby/object:Gem::Version
|
68
54
|
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: bundler
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '1'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '1'
|
83
55
|
- !ruby/object:Gem::Dependency
|
84
56
|
name: rake
|
85
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -166,14 +138,14 @@ files:
|
|
166
138
|
- lib/sym/crypt.rb
|
167
139
|
- lib/sym/crypt/cipher_handler.rb
|
168
140
|
- lib/sym/crypt/configuration.rb
|
169
|
-
- lib/sym/crypt/data.rb
|
170
|
-
- lib/sym/crypt/data/decoder.rb
|
171
|
-
- lib/sym/crypt/data/encoder.rb
|
172
|
-
- lib/sym/crypt/data/wrapper_struct.rb
|
173
141
|
- lib/sym/crypt/errors.rb
|
174
142
|
- lib/sym/crypt/extensions/class_methods.rb
|
175
143
|
- lib/sym/crypt/extensions/instance_methods.rb
|
176
144
|
- lib/sym/crypt/version.rb
|
145
|
+
- lib/sym/data.rb
|
146
|
+
- lib/sym/data/decoder.rb
|
147
|
+
- lib/sym/data/encoder.rb
|
148
|
+
- lib/sym/data/wrapper_struct.rb
|
177
149
|
- sym-crypt.gemspec
|
178
150
|
homepage: https://github.com/kigster/sym-crypt
|
179
151
|
licenses: []
|
@@ -193,8 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
165
|
- !ruby/object:Gem::Version
|
194
166
|
version: '0'
|
195
167
|
requirements: []
|
196
|
-
|
197
|
-
rubygems_version: 2.6.11
|
168
|
+
rubygems_version: 3.0.3
|
198
169
|
signing_key:
|
199
170
|
specification_version: 4
|
200
171
|
summary: Base encryption/decryption core of the encryption app Sym. If you need simple
|
data/lib/sym/crypt/data.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'base64'
|
2
|
-
require 'zlib'
|
3
|
-
|
4
|
-
require 'sym/crypt/data/encoder'
|
5
|
-
require 'sym/crypt/data/decoder'
|
6
|
-
require 'sym/crypt/data/wrapper_struct'
|
7
|
-
|
8
|
-
module Sym
|
9
|
-
module Crypt
|
10
|
-
# This module is responsible for taking arbitrary data of any format, and safely compressing
|
11
|
-
# the result of `Marshal.dump(data)` using Zlib, and then doing `#urlsafe_encode64` encoding
|
12
|
-
# to convert it to a string,
|
13
|
-
module Data
|
14
|
-
def encode(data, compress = true)
|
15
|
-
Encoder.new(data, compress).data_encoded
|
16
|
-
end
|
17
|
-
|
18
|
-
def decode(data_encoded, compress = nil)
|
19
|
-
Decoder.new(data_encoded, compress).data
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'sym/crypt/errors'
|
2
|
-
require 'base64'
|
3
|
-
require 'zlib'
|
4
|
-
|
5
|
-
module Sym
|
6
|
-
module Crypt
|
7
|
-
module Data
|
8
|
-
class Decoder
|
9
|
-
attr_accessor :data, :data_encoded, :data
|
10
|
-
|
11
|
-
def initialize(data_encoded, compress)
|
12
|
-
self.data_encoded = data_encoded
|
13
|
-
self.data = begin
|
14
|
-
Base64.urlsafe_decode64(data_encoded)
|
15
|
-
rescue
|
16
|
-
data_encoded
|
17
|
-
end
|
18
|
-
|
19
|
-
if compress.nil? || compress # auto-guess
|
20
|
-
self.data = begin
|
21
|
-
Zlib::Inflate.inflate(data)
|
22
|
-
rescue Zlib::Error => e
|
23
|
-
data
|
24
|
-
end
|
25
|
-
end
|
26
|
-
self.data = Marshal.load(data)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'base64'
|
2
|
-
require 'zlib'
|
3
|
-
|
4
|
-
require 'sym/crypt/configuration'
|
5
|
-
|
6
|
-
module Sym
|
7
|
-
module Crypt
|
8
|
-
module Data
|
9
|
-
class Encoder
|
10
|
-
attr_accessor :data, :data_encoded
|
11
|
-
|
12
|
-
def initialize(data, compress)
|
13
|
-
self.data = data
|
14
|
-
self.data_encoded = Marshal.dump(data)
|
15
|
-
self.data_encoded = Zlib::Deflate.deflate(data_encoded, compression_level) if compress
|
16
|
-
self.data_encoded = Base64.urlsafe_encode64(data_encoded)
|
17
|
-
end
|
18
|
-
|
19
|
-
def compression_level
|
20
|
-
Sym::Crypt::Configuration.config.compression_level
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
module Sym
|
2
|
-
module Crypt
|
3
|
-
module Data
|
4
|
-
class WrapperStruct < Struct.new(
|
5
|
-
:encrypted_data, # [Blob] Binary encrypted data (possibly compressed)
|
6
|
-
:iv, # [String] IV used to encrypt the data
|
7
|
-
:cipher_name, # [String] Name of the cipher used
|
8
|
-
:salt, # [Integer] For password-encrypted data this is the salt
|
9
|
-
:version, # [Integer] Version of the cipher used
|
10
|
-
:compress # [Boolean] indicates if compression should be applied
|
11
|
-
)
|
12
|
-
|
13
|
-
VERSION = 1
|
14
|
-
|
15
|
-
attr_accessor :compressed
|
16
|
-
|
17
|
-
def initialize(
|
18
|
-
encrypted_data:, # [Blob] Binary encrypted data (possibly compressed)
|
19
|
-
iv:, # [String] IV used to encrypt the data
|
20
|
-
cipher_name:, # [String] Name of the cipher used
|
21
|
-
salt: nil, # [Integer] For password-encrypted data this is the salt
|
22
|
-
version: VERSION, # [Integer] Version of the cipher used
|
23
|
-
compress: Sym::Crypt::Configuration.config.compression_enabled
|
24
|
-
)
|
25
|
-
super(encrypted_data, iv, cipher_name, salt, version, compress)
|
26
|
-
end
|
27
|
-
|
28
|
-
def config
|
29
|
-
Sym::Crypt::Configuration.config
|
30
|
-
end
|
31
|
-
|
32
|
-
def serialize
|
33
|
-
Marshal.dump(self)
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.deserialize(data)
|
37
|
-
Marshal.load(data)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
|