spikex-strongbox 0.1.4 → 0.1.5

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.
Files changed (3) hide show
  1. data/lib/strongbox.rb +1 -1
  2. data/lib/strongbox/lock.rb +20 -1
  3. metadata +2 -2
data/lib/strongbox.rb CHANGED
@@ -5,7 +5,7 @@ require 'strongbox/lock'
5
5
 
6
6
  module Strongbox
7
7
 
8
- VERSION = "0.1.4"
8
+ VERSION = "0.1.5"
9
9
 
10
10
  RSA_PKCS1_PADDING = OpenSSL::PKey::RSA::PKCS1_PADDING
11
11
  RSA_SSLV23_PADDING = OpenSSL::PKey::RSA::SSLV23_PADDING
@@ -8,6 +8,8 @@ module Strongbox
8
8
  @name = name
9
9
  @instance = instance
10
10
 
11
+ @size = nil
12
+
11
13
  options = Strongbox.options.merge(options)
12
14
 
13
15
  @base64 = options[:base64]
@@ -25,6 +27,7 @@ module Strongbox
25
27
  raise StrongboxError.new("#{@instance.class} model does not have public key_file")
26
28
  end
27
29
  if !plaintext.blank?
30
+ @size = plaintext.size # For validations
28
31
  # Using a blank password in OpenSSL::PKey::RSA.new prevents reading
29
32
  # the private key if the file is a key pair
30
33
  public_key = OpenSSL::PKey::RSA.new(File.read(@public_key),"")
@@ -58,13 +61,16 @@ module Strongbox
58
61
  def decrypt password = ""
59
62
  # Given a private key and a nil password OpenSSL::PKey::RSA.new() will
60
63
  # *prompt* for a password, we default to an empty string to avoid that.
64
+ ciphertext = @instance.read_attribute(@name)
65
+ return nil if ciphertext.nil?
66
+ return "" if ciphertext.empty?
67
+
61
68
  return "*encrypted*" if password.blank?
62
69
 
63
70
  unless @private_key
64
71
  raise StrongboxError.new("#{@instance.class} model does not have private key_file")
65
72
  end
66
73
 
67
- ciphertext = @instance.read_attribute(@name)
68
74
  if ciphertext
69
75
  ciphertext = Base64.decode64(ciphertext) if @base64
70
76
  private_key = OpenSSL::PKey::RSA.new(File.read(@private_key),password)
@@ -92,5 +98,18 @@ module Strongbox
92
98
  def to_s
93
99
  decrypt
94
100
  end
101
+
102
+ # Needed for validations
103
+ def blank?
104
+ @instance.read_attribute(@name).blank?
105
+ end
106
+
107
+ def nil?
108
+ @instance.read_attribute(@name).nil?
109
+ end
110
+
111
+ def size
112
+ @size
113
+ end
95
114
  end
96
115
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spikex-strongbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Spike Ilacqua
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-16 23:00:00 -07:00
12
+ date: 2009-04-19 23:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency