secret_keys 1.0.1 → 1.0.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
  SHA256:
3
- metadata.gz: ea7b02c543a0c676946de57cf6b5614a896dd0306d2a9ca6c970369e29d9eb30
4
- data.tar.gz: 99635a343094bf346d73368739e1ab66c2bfbe1ecae0f1eda124a9f7c90bd379
3
+ metadata.gz: 637787c84aaeb9fc38f77ac00f67f38ee4094b0a42ac5fe714a9c10285c65ed7
4
+ data.tar.gz: c57ed55617d13bee4d988d9c0283fff89534ccddd7980f8fa1afe81b5b7b61a4
5
5
  SHA512:
6
- metadata.gz: 077fb2e1b46e7e62a9e3f54315e7e6a98bda74256ab16fa550a8a5cbc0efb34937d1359639f6e91d7102801e114cf079f70415ab091670b99b5c4fc9acf8b63a
7
- data.tar.gz: 3b640dfae9fc3f2ee60763a3bfebb17a12b5a0428743d788d8151c49d7916e2e80249ddcad3e150573d5ae72d9a68c26021b414c1bfb1e15ebfb366ac663c966
6
+ metadata.gz: bfb75203d78bfe74c6c394175cd08a775f3f9415d206f60df941c77ab38c74413cf4e2854a2af3c0208e1e580d0dc3e35f70fd2b59c1d7cd4a7d215a53441efd
7
+ data.tar.gz: b9b1e6ee2be772b78fe9da0ed4768455ce6249e12ff37b6328b9bc197c4ded8638764810a1a23ffcc1820bcfb696f0ed3723b61cdb6af116723e0030068f988a
data/CHANGE_LOG.md CHANGED
@@ -1,9 +1,22 @@
1
1
  # Changelog
2
2
 
3
- ## v1.0.1 (June 01, 2020)
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.0.2] - 2023-04-04
9
+
10
+ - Follow [RFC 4648](https://www.ietf.org/rfc/rfc4648.txt) base 64 encoding, removing line-feeds from the encoded data.
11
+
12
+ ## [1.0.1] - 2020-06-01
13
+
14
+ ### Fixed
4
15
 
5
16
  - Fix missing documentation links
6
17
 
7
- ## v1.0.0 (May 31, 2020)
18
+ ## [1.0.0] 2020-05-31
19
+
20
+ ### Added
8
21
 
9
- Initial release
22
+ - Initial release
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.0.2
@@ -3,7 +3,7 @@
3
3
  require "optparse"
4
4
  require "io/console"
5
5
 
6
- require_relative "../secret_keys.rb"
6
+ require_relative "../secret_keys"
7
7
 
8
8
  module SecretKeys::CLI
9
9
  class Base
@@ -47,7 +47,7 @@ module SecretKeys::CLI
47
47
 
48
48
  def encrypted_file_contents
49
49
  encrypted = secrets.encrypted_hash
50
- string = (format == :yaml ? YAML.dump(encrypted) : JSON.pretty_generate(encrypted))
50
+ string = ((format == :yaml) ? YAML.dump(encrypted) : JSON.pretty_generate(encrypted))
51
51
  string << $/ unless string.end_with?($/) # ensure file ends with system dependent new line
52
52
  string
53
53
  end
@@ -166,8 +166,8 @@ module SecretKeys::CLI
166
166
  @secrets = SecretKeys.new({}, secret_key)
167
167
  if input.is_a?(String)
168
168
  if File.exist?(input)
169
- STDERR.puts "Error: Cannot init preexisting file '#{input}'"
170
- STDERR.puts "You may want to try calling `secret_keys encrypt/edit` instead"
169
+ warn "Error: Cannot init preexisting file '#{input}'"
170
+ warn "You may want to try calling `secret_keys encrypt/edit` instead"
171
171
  exit 1
172
172
  end
173
173
 
@@ -220,9 +220,7 @@ module SecretKeys::CLI
220
220
  raise ArgumentError, "Cannot perform in place editing on streams" unless @input.is_a?(String)
221
221
  # make sure we read the file **before** writing to it.
222
222
  contents = encrypted_file_contents
223
- File.open(@input, "w") do |file|
224
- file.write(contents)
225
- end
223
+ File.write(@input, contents)
226
224
  else
227
225
  $stdout.write(encrypted_file_contents)
228
226
  $stdout.flush
@@ -237,7 +235,7 @@ module SecretKeys::CLI
237
235
 
238
236
  def run!
239
237
  decrypted = secrets.to_h
240
- string = (format == :yaml ? YAML.dump(decrypted) : JSON.pretty_generate(decrypted))
238
+ string = ((format == :yaml) ? YAML.dump(decrypted) : JSON.pretty_generate(decrypted))
241
239
  string << $/ unless string.end_with?($/) # ensure file ends with system dependent new line
242
240
  $stdout.write(string)
243
241
  $stdout.flush
@@ -2,7 +2,6 @@
2
2
 
3
3
  require "securerandom"
4
4
  require "openssl"
5
- require "base64"
6
5
 
7
6
  # Encyption helper for encrypting and decrypting values using AES-256-GCM and returning
8
7
  # as Base64 encoded strings. The encrypted values also include a prefix that can be used
@@ -138,13 +137,13 @@ class SecretKeys::Encryptor
138
137
  # Receive a cipher object (initialized with key) and data
139
138
  def encode_aes(params)
140
139
  encoded = params.values.pack(ENCODING_FORMAT)
141
- # encode base64 and get rid of trailing newline and unnecessary =
142
- Base64.encode64(encoded).chomp.tr("=", "")
140
+ # encode base64 and get rid of unnecessary '=' padding
141
+ [encoded].pack("m0").tr("=", "")
143
142
  end
144
143
 
145
144
  # Passed in an aes encoded string and returns a cipher object
146
145
  def decode_aes(str)
147
- unpacked_data = Base64.decode64(str).unpack(ENCODING_FORMAT)
146
+ unpacked_data = str.unpack1("m").unpack(ENCODING_FORMAT)
148
147
  # Splat the data array apart
149
148
  # nonce, auth_tag, encrypted_data = unpacked_data
150
149
  CipherParams.new(*unpacked_data)
data/lib/secret_keys.rb CHANGED
@@ -44,7 +44,7 @@ class SecretKeys < DelegateClass(Hash)
44
44
  def to_h
45
45
  @values
46
46
  end
47
- alias to_hash to_h
47
+ alias_method :to_hash, :to_h
48
48
 
49
49
  # Mark the key as being encrypted when the JSON is saved.
50
50
  #
@@ -94,11 +94,9 @@ class SecretKeys < DelegateClass(Hash)
94
94
  format ||= @format
95
95
  format = format.to_s.downcase
96
96
 
97
- output = (format == "yaml" ? YAML.dump(encrypted) : JSON.pretty_generate(encrypted))
97
+ output = ((format == "yaml") ? YAML.dump(encrypted) : JSON.pretty_generate(encrypted))
98
98
  output << $/ unless output.end_with?($/) # ensure file ends with system dependent new line
99
- File.open(path, "w") do |file|
100
- file.write(output)
101
- end
99
+ File.write(path, output)
102
100
  nil
103
101
  end
104
102
 
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: secret_keys
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand
8
8
  - Winston Durand
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-06-01 00:00:00.000000000 Z
12
+ date: 2023-04-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -25,7 +25,7 @@ dependencies:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: '2.0'
28
- description:
28
+ description:
29
29
  email:
30
30
  - bbdurand@gmail.com
31
31
  - me@winstondurand.com
@@ -49,9 +49,9 @@ licenses:
49
49
  - MIT
50
50
  metadata:
51
51
  homepage_uri: https://github.com/bdurand/secret_keys
52
- source_code_uri: https://github.com/bdurand/secret_keys/tree/v1.0.1
52
+ source_code_uri: https://github.com/bdurand/secret_keys/tree/v1.0.2
53
53
  documentation_uri: https://www.rubydoc.info/gems/secret_keys
54
- post_install_message:
54
+ post_install_message:
55
55
  rdoc_options: []
56
56
  require_paths:
57
57
  - lib
@@ -66,8 +66,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
68
  requirements: []
69
- rubygems_version: 3.1.2
70
- signing_key:
69
+ rubygems_version: 3.2.22
70
+ signing_key:
71
71
  specification_version: 4
72
72
  summary: Simple mechanism for loading JSON file with encrypted values.
73
73
  test_files: []