porky_lib 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f7a8b165ff0aea52419016bda857aa54eed937a
4
- data.tar.gz: 42e0ecf5da4705ec06d4caca5ad5c0ac0b8b4b28
3
+ metadata.gz: 6b6d99825e31f9e850ee090a293d5f704a34f294
4
+ data.tar.gz: 0cba4761cd98912a5e0eafd05513a76d2ab1034a
5
5
  SHA512:
6
- metadata.gz: 6eb4d547ffe82efea3a1689e725c14fa6e2493e5fc3a955884f7c6a327f3b5b7eb7e7d0c9c9f2fbc5132de532fc11582aaf6682da8cbb688f5751c4f235565cd
7
- data.tar.gz: d529b67755e6dec6724e8d9cda9323328a7e17f6e06eac468a47f8f77233e3ddc1e8a03f955e45a18eae0b8d9e16818e07f65ed6103dbb59e5dcc6453f719b02
6
+ metadata.gz: fa521fe6af8be9205a7bf1089c993ed3fae376a74e773493becf454ae9d130830835c2519511438e8b52a0934e172aec1fdfadbb765ccc0ade9e10a3641a4a3e
7
+ data.tar.gz: 63879795dd9a84871cc2dfbca684f2084d04190562863e8af5a37ecaad281834567758801f6e4069cde868855018455322053808eb6c851f9e64f07eb1b4fa31
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- porky_lib (0.3.1)
4
+ porky_lib (0.3.2)
5
5
  aws-sdk-kms
6
6
  aws-sdk-s3
7
7
  msgpack
@@ -13,16 +13,16 @@ GEM
13
13
  specs:
14
14
  ast (2.4.0)
15
15
  aws-eventstream (1.0.1)
16
- aws-partitions (1.115.0)
17
- aws-sdk-core (3.39.0)
16
+ aws-partitions (1.117.0)
17
+ aws-sdk-core (3.40.0)
18
18
  aws-eventstream (~> 1.0)
19
19
  aws-partitions (~> 1.0)
20
20
  aws-sigv4 (~> 1.0)
21
21
  jmespath (~> 1.0)
22
- aws-sdk-kms (1.12.0)
22
+ aws-sdk-kms (1.13.0)
23
23
  aws-sdk-core (~> 3, >= 3.39.0)
24
24
  aws-sigv4 (~> 1.0)
25
- aws-sdk-s3 (1.25.0)
25
+ aws-sdk-s3 (1.27.0)
26
26
  aws-sdk-core (~> 3, >= 3.39.0)
27
27
  aws-sdk-kms (~> 1)
28
28
  aws-sigv4 (~> 1.0)
@@ -77,8 +77,8 @@ GEM
77
77
  rainbow (>= 2.2.2, < 4.0)
78
78
  ruby-progressbar (~> 1.7)
79
79
  unicode-display_width (~> 1.4.0)
80
- rubocop-rspec (1.29.1)
81
- rubocop (>= 0.58.0)
80
+ rubocop-rspec (1.30.1)
81
+ rubocop (>= 0.60.0)
82
82
  rubocop_runner (2.1.0)
83
83
  ruby-progressbar (1.10.0)
84
84
  simplecov (0.16.1)
@@ -30,7 +30,7 @@ class PorkyLib::FileService
30
30
 
31
31
  data = file_data(file)
32
32
  file_key = options.key?(:directory) ? "#{options[:directory]}/#{SecureRandom.uuid}" : SecureRandom.uuid
33
- tempfile = encrypt_file_contents(data, key_id, file_key)
33
+ tempfile = encrypt_file_contents(data, key_id, file_key, options)
34
34
 
35
35
  begin
36
36
  perform_upload(bucket_name, file_key, tempfile, options)
@@ -49,7 +49,7 @@ class PorkyLib::FileService
49
49
  raise FileSizeTooLargeError, "File size is larger than maximum allowed size of #{max_file_size}" if file_size_invalid?(file)
50
50
 
51
51
  data = file_data(file)
52
- tempfile = encrypt_file_contents(data, key_id, file_key)
52
+ tempfile = encrypt_file_contents(data, key_id, file_key, options)
53
53
 
54
54
  begin
55
55
  perform_upload(bucket_name, file_key, tempfile, options)
@@ -111,16 +111,26 @@ class PorkyLib::FileService
111
111
  PorkyLib::Symmetric.instance.decrypt(ciphertext_key, ciphertext, nonce)
112
112
  end
113
113
 
114
- def encrypt_file_contents(file, key_id, file_key)
114
+ def encrypt_file_contents(file, key_id, file_key, options)
115
115
  ciphertext_key, ciphertext, nonce = PorkyLib::Symmetric.instance.encrypt(file, key_id)
116
+ write_tempfile(file_contents(ciphertext_key, ciphertext, nonce, options), file_key)
117
+ end
118
+
119
+ def file_contents(ciphertext_key, ciphertext, nonce, options)
120
+ if options.is_a?(Hash) && options.key?(:metadata) && !options[:metadata].nil?
121
+ return {
122
+ key: Base64.urlsafe_encode64(ciphertext_key),
123
+ data: Base64.urlsafe_encode64(ciphertext),
124
+ nonce: Base64.urlsafe_encode64(nonce),
125
+ metadata: options[:metadata]
126
+ }.to_json
127
+ end
116
128
 
117
- file_contents = {
129
+ {
118
130
  key: Base64.urlsafe_encode64(ciphertext_key),
119
131
  data: Base64.urlsafe_encode64(ciphertext),
120
132
  nonce: Base64.urlsafe_encode64(nonce)
121
133
  }.to_json
122
-
123
- write_tempfile(file_contents, file_key)
124
134
  end
125
135
 
126
136
  def write_tempfile(file_contents, file_key)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PorkyLib
4
- VERSION = "0.3.1"
4
+ VERSION = "0.3.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: porky_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Fletcher
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-23 00:00:00.000000000 Z
11
+ date: 2018-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler