cryptic 1.0.0.beta.5 → 1.0.0.beta.6
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/cryptic +0 -1
- data/lib/cryptic/encrypted_data.rb +12 -10
- data/lib/cryptic/version.rb +1 -1
- metadata +2 -2
data/bin/cryptic
CHANGED
@@ -18,30 +18,29 @@ module Cryptic
|
|
18
18
|
# @note If called without a public key's file name this doesn't
|
19
19
|
# automatically encrypt the data
|
20
20
|
# @param [String] data the data to encrypt
|
21
|
-
# @param [String]
|
21
|
+
# @param [String] public_key the public key to use in # TODO: Update the indent right here
|
22
22
|
# the encryption process
|
23
23
|
# @param [Symbol] encoding the encoding to use
|
24
|
+
# @todo Document the opts hash
|
25
|
+
# @todo Create an encrypt method to clean up this code
|
24
26
|
# @raise [KeyNotFound] if the specified public key wasn't found on the
|
25
27
|
# file system
|
26
28
|
# @return [EncryptedData] an encrypted data object
|
27
|
-
def initialize(data,
|
29
|
+
def initialize(data, public_key = nil, encoding = :none, opts = {})
|
28
30
|
@encoding = encoding
|
29
31
|
|
30
|
-
if !public_key_file
|
32
|
+
if !public_key && !opts[:public_key_file]
|
31
33
|
# If no public key was provided the data should already be encrypted
|
32
34
|
@data = data
|
33
|
-
elsif File.exists?(public_key_file.to_s)
|
35
|
+
elsif File.exists?(opts[:public_key_file].to_s)
|
34
36
|
public_key = OpenSSL::PKey::RSA.new(File.read(public_key_file))
|
35
37
|
encrypted_data = public_key.public_encrypt(data)
|
36
38
|
@data = encode(encrypted_data)
|
37
|
-
|
38
|
-
public_key = OpenSSL::PKey::RSA.new(
|
39
|
+
elsif public_key
|
40
|
+
public_key = OpenSSL::PKey::RSA.new(public_key)
|
39
41
|
encrypted_data = public_key.public_encrypt(data)
|
40
42
|
@data = encode(encrypted_data)
|
41
43
|
end
|
42
|
-
rescue => e
|
43
|
-
$stderr.puts e
|
44
|
-
raise Cryptic::KeyNotFound
|
45
44
|
end
|
46
45
|
|
47
46
|
# Creates a new encrypted data object from an encrypted data string
|
@@ -62,6 +61,9 @@ module Cryptic
|
|
62
61
|
# @param [String] passphrase the passphrase to unlock the private key with
|
63
62
|
# @raise [KeyNotFound] if the specified public key wasn't found on the
|
64
63
|
# file system
|
64
|
+
# @todo Use the opts syntax like in initialize
|
65
|
+
# @todo Update the this method with encrypt in code cleanup
|
66
|
+
# @return [String] the unencrypted data
|
65
67
|
def decrypt(private_key_file, passphrase = nil)
|
66
68
|
if File.exists?(private_key_file.to_s)
|
67
69
|
private_key = OpenSSL::PKey::RSA.new(File.read(private_key_file), passphrase)
|
@@ -80,7 +82,7 @@ module Cryptic
|
|
80
82
|
# @return [String] the encrypted data string
|
81
83
|
def to_s; @data; end
|
82
84
|
|
83
|
-
private
|
85
|
+
private # TODO: Determine whether to use private here or not
|
84
86
|
|
85
87
|
# TODO: The decode/encode methods shouldn't share so much code
|
86
88
|
# TODO: These methods also shouldn't raise an exception that could be raised
|
data/lib/cryptic/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cryptic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.beta.
|
4
|
+
version: 1.0.0.beta.6
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -167,7 +167,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
167
167
|
version: '0'
|
168
168
|
segments:
|
169
169
|
- 0
|
170
|
-
hash: -
|
170
|
+
hash: -2304157530869896599
|
171
171
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
172
|
none: false
|
173
173
|
requirements:
|