secure_string 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -83,10 +83,10 @@ Additionally, you can get at the byte data in various ways:
83
83
 
84
84
  One can initialize a SecureString from any of these types like so:
85
85
 
86
- ss1 = SecureString.new(:data, "Hello World!")
87
- ss2 = SecureString.new(:hex, "48656c6c6f20576f726c6421")
88
- ss3 = SecureString.new(:int, 22405534230753928650781647905)
89
- ss4 = SecureString.new(:base64, "SGVsbG8gV29ybGQh")
86
+ ss1 = SecureString.new("Hello World!", :type => :data)
87
+ ss2 = SecureString.new("48656c6c6f20576f726c6421", :type => :hex)
88
+ ss3 = SecureString.new(22405534230753928650781647905, :type => :int)
89
+ ss4 = SecureString.new("SGVsbG8gV29ybGQh", :type => :base64)
90
90
 
91
91
  ss1 == ss --> true
92
92
  ss2 == ss --> true
@@ -104,9 +104,9 @@ The SecureString::Base64Methods module adds +to_base64+, which we've seen:
104
104
  It also adds +from_base64+, which can decode a Base64 encoded string. The
105
105
  following example shows the various ways of decoding Bas64 data:
106
106
 
107
- SecureString.new(:base64, "SGVsbG8gV29ybGQh") == "Hello World!" --> true
108
- SecureString.new("SGVsbG8gV29ybGQh") == "Hello World!" --> false
109
- SecureString.new("SGVsbG8gV29ybGQh").from_base64 == "Hello World!" --> true
107
+ SecureString.new("SGVsbG8gV29ybGQh", :type => :base64) == "Hello World!" --> true
108
+ SecureString.new("SGVsbG8gV29ybGQh") == "Hello World!" --> false
109
+ SecureString.new("SGVsbG8gV29ybGQh").from_base64 == "Hello World!" --> true
110
110
 
111
111
  == Digest Methods Overview
112
112
 
@@ -234,6 +234,11 @@ or directly via e-mail at:
234
234
  mailto:jeff@paploo.net
235
235
 
236
236
  = Version History
237
+ [1.3.0 - 2011-Jun-15] Ruby 1.8 compatibility.
238
+ * (FEATURE) Emulation urlsafe base64 encodings in ruby 1.8.
239
+ * (CHANGE) SecureString.new arguments changed to work with ruby 1.8.
240
+ Instead of specifying the argument type hint first, you now do that with an options hash.
241
+ (You will get a descriptive error if you try to do it the old way.)
237
242
  [1.2.1 - 2011-Jun-15] Bugfixes
238
243
  * (FIX) To/From Base64 methods were returning normal strings, making chaining impossible.
239
244
  [1.2.0 - 2011-May-17] Re-wrote Base64 module to address problems with RFC 2045 vs. RFC 4648 compatibility.
data/lib/secure_string.rb CHANGED
@@ -1,4 +1,4 @@
1
- require_relative 'securize_string'
1
+ require File.join(File.dirname(__FILE__), 'securize_string')
2
2
 
3
3
  # SecureString is a String subclass whose emphasis is on byte data rather than
4
4
  # human readable strings. class gives a number of conveniences, such
@@ -12,9 +12,11 @@ class SecureString < String
12
12
  # [:hex] Initialize using a hexidecimal string.
13
13
  # [:int] Initialize using the numeric value of the hexidecimal string.
14
14
  # [:base64] Initialize using the given base64 encoded data.
15
- def initialize(mode = :data, value)
16
- data_string = self.class.parse_data(mode, value)
17
- self.replace( data_string )
15
+ # To specify a value kind, pass the :type option.
16
+ def initialize(value, opts={})
17
+ raise ArgumentError, "The first argument is a symbol; setting the input data type this way is no longer supported. Call `#{self.class.name}.new('string', :type => #{value.inspect})' instead.", caller if value.kind_of?(Symbol)
18
+ data_string = self.class.parse_data(value, opts)
19
+ self.replace(data_string)
18
20
  end
19
21
 
20
22
  # Override the default to_i method to return the integer value of the data
@@ -25,7 +25,7 @@ module SecurizeString
25
25
  # removed from the input.
26
26
  def to_base64(opts={})
27
27
  raise ArgumentError, "__method__ expects an argument hash but got #{opts.class.name}" unless opts.kind_of?(Hash)
28
- data = (opts[:url_safe] ? Base64.urlsafe_encode64(self) : Base64.encode64(self))
28
+ data = (opts[:url_safe] ? urlsafe_encode64(self) : Base64.encode64(self))
29
29
  data.delete!("\n\r") if opts[:no_break] # Delete on \n and \r is about 3x faster than gsub on /\s+/.
30
30
  return self.class.new(data)
31
31
  end
@@ -39,10 +39,42 @@ module SecurizeString
39
39
  # which is sometimes compatible, but often incompatible with RFC 2045.
40
40
  def from_base64(opts={})
41
41
  raise ArgumentError, "__method__ expects an argument hash but got #{opts.class.name}" unless opts.kind_of?(Hash)
42
- string = (opts[:url_safe] ? Base64.urlsafe_decode64(self) : Base64.decode64(self))
42
+ string = (opts[:url_safe] ? urlsafe_decode64(self) : Base64.decode64(self))
43
43
  return self.class.new(string)
44
44
  end
45
45
 
46
+ private
47
+
48
+ # URL Safe encoding.
49
+ #
50
+ # Ruby 1.8 does not ship with this method, so we emulate it as best we
51
+ # can if it is missing.
52
+ def urlsafe_encode64(str)
53
+ if( Base64.respond_to?(:urlsafe_encode64) )
54
+ return Base64.urlsafe_encode64(str)
55
+ else
56
+ # This *should* work out the same.
57
+ return Base64.encode64(str).delete!("\n\r").tr("+/", "-_")
58
+ end
59
+ end
60
+
61
+ # URL Safe decoding.
62
+ #
63
+ # Ruby 1.8 does not ship with this method, so we emulate it as best we
64
+ # can if it is missing.
65
+ def urlsafe_decode64(str)
66
+ if( Base64.respond_to?(:urlsafe_decode64) )
67
+ return Base64.urlsafe_decode64(str)
68
+ else
69
+ # To emulate the 1.9.2 strictness check, if we have any illegal characters, throw
70
+ # the same error that 1.9.2 does.
71
+ # Note that we can take characters from before and after the tr substitution fine.
72
+ # a-z, A-Z, 0-9, -, _, +, and / are valid characters
73
+ raise ArgumentError, "invalid base64" if str =~ /[^-a-zA-Z0-9_+\/]/
74
+ return Base64.decode64( str.tr("-_", "+/") )
75
+ end
76
+ end
77
+
46
78
  end
47
79
 
48
80
  end
@@ -18,17 +18,22 @@ module SecurizeString
18
18
  # [:hex] Initialize using a hexidecimal string.
19
19
  # [:int] Initialize using the numeric value of the hexidecimal string.
20
20
  # [:base64] Initialize using the given base64 encoded data.
21
- def parse_data(mode = :data, value)
22
- case mode
21
+ # To specify a value kind, use the :type option.
22
+ def parse_data(value, opts={})
23
+ raise ArgumentError, "The first argument is a symbol; setting the input data type this way is no longer supported. Call `#{self.class.name}.new('string', :type => #{value.inspect})' instead.", caller if value.kind_of?(Symbol)
24
+ data_type_hint = (opts[:data_type_hint] || opts[:type] || :data).to_sym
25
+ case data_type_hint
23
26
  when :hex
24
27
  hex_string = value.to_s.delete('^0-9a-fA-F')
25
28
  data_string = [hex_string].pack('H' + hex_string.bytesize.to_s)
26
29
  when :data
27
30
  data_string = value.to_s
28
31
  when :int
29
- data_string = self.send(__method__, :hex, value.to_i.to_s(16))
32
+ data_string = self.send(__method__, value.to_i.to_s(16), :type => :hex)
30
33
  when :base64
31
34
  data_string = Base64.decode64(value.to_s)
35
+ else
36
+ raise ArgumentError, "Unrecognized data type hint: #{data_type_hint.inspect}"
32
37
  end
33
38
 
34
39
  return data_string
@@ -1,5 +1,5 @@
1
1
  require 'openssl'
2
- require_relative 'digest_finder'
2
+ require File.join(File.dirname(__FILE__), 'digest_finder')
3
3
 
4
4
  module SecurizeString
5
5
  # Adds methods for OpenSSL::Digest support.
@@ -1,8 +1,12 @@
1
- require_relative 'securize_string/binary_string_data_methods'
2
- require_relative 'securize_string/digest_methods'
3
- require_relative 'securize_string/base64_methods'
4
- require_relative 'securize_string/cipher_methods'
5
- require_relative 'securize_string/rsa_methods'
1
+ [
2
+ 'binary_string_data_methods',
3
+ 'digest_methods',
4
+ 'base64_methods',
5
+ 'cipher_methods',
6
+ 'rsa_methods'
7
+ ].each do |module_file_name|
8
+ require File.join(File.dirname(__FILE__), 'securize_string', module_file_name)
9
+ end
6
10
 
7
11
  module SecurizeString
8
12
 
@@ -19,8 +19,10 @@ describe "SecureString" do
19
19
  it 'should convert self to Base64; URL safe' do
20
20
  @messages.each do |message|
21
21
  ss = SecureString.new(message[:string])
22
- # Compare the result with the base ruby methods.
23
- ss.to_base64(:url_safe => true).should == Base64.urlsafe_encode64(message[:string])
22
+ # If the version of ruby has :urlsafe_encode64, then we dynamically build to
23
+ # make sure the implementation hasn't changed; otherwise use the pre-cached string.
24
+ urlsafe_string = (Base64.respond_to?(:urlsafe_encode64)) ? Base64.urlsafe_encode64(message[:string]) : message[:urlsafe_base64]
25
+ ss.to_base64(:url_safe => true).should == urlsafe_string
24
26
  end
25
27
  end
26
28
 
@@ -59,10 +59,10 @@ describe "SecureString" do
59
59
 
60
60
  before(:all) do
61
61
  @cipher = "DES"
62
- @key = SecureString.new(:hex, "4f42383e091ffc44")
63
- @iv = SecureString.new(:hex, "0b9299d6c2cb5003")
62
+ @key = SecureString.new("4f42383e091ffc44", :type => :hex)
63
+ @iv = SecureString.new("0b9299d6c2cb5003", :type => :hex)
64
64
  @message = SecureString.new("We the People of the United States, in Order to form a more perfect Union, establish Justice, insure domestic Tranquility, provide for the common defence, promote the general Welfare, and secure the Blessings of Liberty to ourselves and our Posterity, do ordain and establish this Constitution for the United States of America.")
65
- @encoded_message = SecureString.new(:hex, "cfe8245b2c1f3f789b8ab78930c9582d1fead6792d8fe7efd418ba06d7da4e96f8525e8b437cf29af71ec66801c2031292fc17d88f5aaa9c776b3ca048169b48394e05d5ae6cbba5c78461a25bc3d5abc646f5f760e3a159b8448d79eed80a209473ca67536ebf417a24f05cf029e9e3ca5b1fb22e4e03427705d79b622d720c7d64cf3621319581a1a89b4cbb630611eea29cbd2c48caef0cf774ea0218b16d600cb4c025dcae177b702040bd7c62569bbda33f8e775dbadba4154074f482385c56449882efa31b908dfe5be17d8c0d220fd99414a78f6ce3cfee007fbd5dfc7fd50c343e6118d1a9174bb75db7c5adbaa558010f56571d087982ae791960c31041bae08adfa4d1a88f457897e38bd56a7e92234d21c8742fa577878b2d65500877d2f910d1fdbb5460afa73642778de8bd4442981baa93a481482f1cfb90fa85025ddf8588ecc7")
65
+ @encoded_message = SecureString.new("cfe8245b2c1f3f789b8ab78930c9582d1fead6792d8fe7efd418ba06d7da4e96f8525e8b437cf29af71ec66801c2031292fc17d88f5aaa9c776b3ca048169b48394e05d5ae6cbba5c78461a25bc3d5abc646f5f760e3a159b8448d79eed80a209473ca67536ebf417a24f05cf029e9e3ca5b1fb22e4e03427705d79b622d720c7d64cf3621319581a1a89b4cbb630611eea29cbd2c48caef0cf774ea0218b16d600cb4c025dcae177b702040bd7c62569bbda33f8e775dbadba4154074f482385c56449882efa31b908dfe5be17d8c0d220fd99414a78f6ce3cfee007fbd5dfc7fd50c343e6118d1a9174bb75db7c5adbaa558010f56571d087982ae791960c31041bae08adfa4d1a88f457897e38bd56a7e92234d21c8742fa577878b2d65500877d2f910d1fdbb5460afa73642778de8bd4442981baa93a481482f1cfb90fa85025ddf8588ecc7", :type => :hex)
66
66
  end
67
67
 
68
68
  it 'should encode to a SecureString' do
@@ -88,10 +88,10 @@ describe "SecureString" do
88
88
  describe "AES" do
89
89
 
90
90
  before(:all) do
91
- @key = SecureString.new(:hex, "83f8577c1bc406e85ceeebc166c9fd4d087670de792b0d957c58f1beae6fb514")
92
- @iv = SecureString.new(:hex, "778c1086b5daf809e7abadde6995219d")
91
+ @key = SecureString.new("83f8577c1bc406e85ceeebc166c9fd4d087670de792b0d957c58f1beae6fb514", :type => :hex)
92
+ @iv = SecureString.new("778c1086b5daf809e7abadde6995219d", :type => :hex)
93
93
  @message = SecureString.new("We the People of the United States, in Order to form a more perfect Union, establish Justice, insure domestic Tranquility, provide for the common defence, promote the general Welfare, and secure the Blessings of Liberty to ourselves and our Posterity, do ordain and establish this Constitution for the United States of America.")
94
- @encoded_message = SecureString.new(:hex, "1fee4d01d33daf50915dc4b7aaf8b536f3b19ee9798b21200d475925460fd3aabc581d89e560b7b826e6017e02911687425d9c4a781d8e03a9d75dab5a85191f86b11fb74063133c3952201a8f2089afb0e298e29fe8becbe93ce110073b9abb968a268857aaabd94caa760fa402ce803f8643ad8870e77714b093e9ea09a4ad9d7e056836939f614a61f6b3e09057bc05f13432aa53cfc7de59d41a121f9fcb7c51825da2615c48debff6ed0fbaa0c85594aef54e11b73b8766f6e56d2cf7488909c14272e846cccca0008599bae334c5d404c122d286dcf04eec7b7711978686a66182f53e569297b91c25100ecfdad1f02de444c4de8f9d04067e885a2a17cad707b51ea8c2e8a15051138de617f8864cca8a4d201246a97b95cee5f78f742aace79629e03498f63b6385cff64d53a0425f7f52c6a8ba65771e043590b61191804fe91760e617412d842831928e57")
94
+ @encoded_message = SecureString.new("1fee4d01d33daf50915dc4b7aaf8b536f3b19ee9798b21200d475925460fd3aabc581d89e560b7b826e6017e02911687425d9c4a781d8e03a9d75dab5a85191f86b11fb74063133c3952201a8f2089afb0e298e29fe8becbe93ce110073b9abb968a268857aaabd94caa760fa402ce803f8643ad8870e77714b093e9ea09a4ad9d7e056836939f614a61f6b3e09057bc05f13432aa53cfc7de59d41a121f9fcb7c51825da2615c48debff6ed0fbaa0c85594aef54e11b73b8766f6e56d2cf7488909c14272e846cccca0008599bae334c5d404c122d286dcf04eec7b7711978686a66182f53e569297b91c25100ecfdad1f02de444c4de8f9d04067e885a2a17cad707b51ea8c2e8a15051138de617f8864cca8a4d201246a97b95cee5f78f742aace79629e03498f63b6385cff64d53a0425f7f52c6a8ba65771e043590b61191804fe91760e617412d842831928e57", :type => :hex)
95
95
  end
96
96
 
97
97
  it 'should encode to a SecureString' do
data/spec/example_spec.rb CHANGED
@@ -12,10 +12,10 @@ describe "Examples" do
12
12
  ss.to_i.should == 22405534230753928650781647905
13
13
  ss.to_base64.should == "SGVsbG8gV29ybGQh\n"
14
14
 
15
- ss1 = SecureString.new(:data, "Hello World!")
16
- ss2 = SecureString.new(:hex, "48656c6c6f20576f726c6421")
17
- ss3 = SecureString.new(:int, 22405534230753928650781647905)
18
- ss4 = SecureString.new(:base64, "SGVsbG8gV29ybGQh")
15
+ ss1 = SecureString.new("Hello World!", :type => :data)
16
+ ss2 = SecureString.new("48656c6c6f20576f726c6421", :type => :hex)
17
+ ss3 = SecureString.new(22405534230753928650781647905, :type => :int)
18
+ ss4 = SecureString.new("SGVsbG8gV29ybGQh", :type => :base64)
19
19
 
20
20
  ss1.should == ss
21
21
  ss2.should == ss
@@ -26,9 +26,9 @@ describe "Examples" do
26
26
  it 'should perform the base64 example' do
27
27
  SecureString.new("Hello World!").to_base64.should == "SGVsbG8gV29ybGQh\n"
28
28
 
29
- (SecureString.new(:base64, "SGVsbG8gV29ybGQh") == "Hello World!" ).should be_true
30
- (SecureString.new("SGVsbG8gV29ybGQh") == "Hello World!" ).should be_false
31
- (SecureString.new("SGVsbG8gV29ybGQh").from_base64 == "Hello World!").should be_true
29
+ (SecureString.new("SGVsbG8gV29ybGQh", :type => :base64) == "Hello World!").should be_true
30
+ (SecureString.new("SGVsbG8gV29ybGQh") == "Hello World!" ).should be_false
31
+ (SecureString.new("SGVsbG8gV29ybGQh").from_base64 == "Hello World!" ).should be_true
32
32
  end
33
33
 
34
34
  it 'should perform digest example' do
@@ -54,22 +54,24 @@ describe "Examples" do
54
54
  cipher_text.should_not == message
55
55
  end
56
56
 
57
- it 'should perform the char encoding example' do
58
- s = "Resum\u00E9"
59
- s.encoding.should == Encoding.find("UTF-8")
60
- s.length.should == 6
61
- s.bytesize.should == 7
57
+ if( RUBY_VERSION >= '1.9.0' )
58
+ it 'should perform the char encoding example' do
59
+ s = "Resum\u00E9"
60
+ s.encoding.should == Encoding.find("UTF-8")
61
+ s.length.should == 6
62
+ s.bytesize.should == 7
62
63
 
63
- s = "Resum\u00E9"
64
- s.force_encoding('BINARY')
65
- s.encoding.should == Encoding.find("ASCII-8BIT")
66
- s.length.should == 7
67
- s.bytesize.should == 7
64
+ s = "Resum\u00E9"
65
+ s.force_encoding('BINARY')
66
+ s.encoding.should == Encoding.find("ASCII-8BIT")
67
+ s.length.should == 7
68
+ s.bytesize.should == 7
68
69
 
69
- s = "Resum\u00E9"
70
- b = s.dup.force_encoding('BINARY')
71
- (s == b).should be_false
72
- (s.bytes.to_a == b.bytes.to_a).should be_true
70
+ s = "Resum\u00E9"
71
+ b = s.dup.force_encoding('BINARY')
72
+ (s == b).should be_false
73
+ (s.bytes.to_a == b.bytes.to_a).should be_true
74
+ end
73
75
  end
74
76
 
75
77
  end
@@ -22,31 +22,31 @@ describe "SecureString" do
22
22
 
23
23
  it 'should initialize from hex' do
24
24
  @messages.each do |message|
25
- ss = SecureString.new(:hex, message[:hex])
25
+ ss = SecureString.new(message[:hex], :type => :hex)
26
26
  ss.should == message[:string]
27
27
 
28
- ss = SecureString.new(:hex, message[:hex].upcase)
28
+ ss = SecureString.new(message[:hex].upcase, :type => :hex)
29
29
  ss.should == message[:string]
30
30
  end
31
31
  end
32
32
 
33
33
  it 'should initialize from data' do
34
34
  @messages.each do |message|
35
- ss = SecureString.new(:data, message[:string])
35
+ ss = SecureString.new(message[:string], :type => :data)
36
36
  ss.should == message[:string]
37
37
  end
38
38
  end
39
39
 
40
40
  it 'should initialize from int' do
41
41
  @messages.each do |message|
42
- ss = SecureString.new(:int, message[:int])
42
+ ss = SecureString.new(message[:int], :type => :int)
43
43
  ss.should == message[:string]
44
44
  end
45
45
  end
46
46
 
47
47
  it 'should initialize from Base64' do
48
48
  @messages.each do |message|
49
- ss = SecureString.new(:base64, message[:base64])
49
+ ss = SecureString.new(message[:base64], :type => :base64)
50
50
  ss.should == message[:string]
51
51
  end
52
52
 
@@ -59,7 +59,11 @@ describe "SecureString" do
59
59
  end
60
60
 
61
61
  it 'should implement to_hex' do
62
- SecureString.instance_methods.should include(:to_hex)
62
+ if( RUBY_VERSION >= '1.9.0' )
63
+ SecureString.instance_methods.should include(:to_hex)
64
+ else
65
+ SecureString.instance_methods.should include('to_hex')
66
+ end
63
67
 
64
68
  @messages.each do |message|
65
69
  ss = SecureString.new(message[:string])
@@ -68,7 +72,11 @@ describe "SecureString" do
68
72
  end
69
73
 
70
74
  it 'should implement to_i properly' do
71
- SecureString.instance_methods.should include(:to_i)
75
+ if( RUBY_VERSION >= '1.9.0' )
76
+ SecureString.instance_methods.should include(:to_i)
77
+ else
78
+ SecureString.instance_methods.should include('to_i')
79
+ end
72
80
 
73
81
  @messages.each do |message|
74
82
  ss = SecureString.new(message[:string])
@@ -89,7 +97,7 @@ describe "SecureString" do
89
97
  35563e0d 8bdf572f 77b53065 cef31f32 dc9dbaa0 4146261e 9994bd5c d0758e3d"
90
98
  DATA
91
99
 
92
- ss = SecureString.new(:hex, data)
100
+ ss = SecureString.new(data, :type => :hex)
93
101
 
94
102
  # This was taken from a publically published SHA-0 data collision document,
95
103
  # so the best way to know that the data is good is to SHA-0 it and see if
@@ -97,33 +105,35 @@ describe "SecureString" do
97
105
  OpenSSL::Digest::SHA.hexdigest(ss).should == "c9f160777d4086fe8095fba58b7e20c228a4006b"
98
106
  end
99
107
 
100
- describe 'Encodings' do
108
+ if( RUBY_VERSION >= '1.9.0' )
109
+ describe 'Encodings' do
101
110
 
102
- before(:each) do
103
- @unicode_string = "A resumé for the moose; Eine Zusammenfassung für die Elche; Резюме для лосей; アメリカヘラジカのための概要; Μια περίληψη για τις άλκες; 麋的一份簡歷; Un résumé pour les orignaux."
104
- end
111
+ before(:each) do
112
+ @unicode_string = "A resumé for the moose; Eine Zusammenfassung für die Elche; Резюме для лосей; アメリカヘラジカのための概要; Μια περίληψη για τις άλκες; 麋的一份簡歷; Un résumé pour les orignaux."
113
+ end
105
114
 
106
- it 'should NOT change the encoding of a string' do
107
- @unicode_string.encoding.should == Encoding.find("UTF-8")
108
- ss = SecureString.new(@unicode_string)
109
- ss.encoding.should == @unicode_string.encoding
110
- end
115
+ it 'should NOT change the encoding of a string' do
116
+ @unicode_string.encoding.should == Encoding.find("UTF-8")
117
+ ss = SecureString.new(@unicode_string)
118
+ ss.encoding.should == @unicode_string.encoding
119
+ end
111
120
 
112
- it 'should NOT change the length to the byte count for UTF-8 encoded strings.' do
113
- @unicode_string.encoding.should == Encoding.find("UTF-8")
114
- ss = SecureString.new(@unicode_string)
115
- ss.length.should < ss.bytesize
116
- end
121
+ it 'should NOT change the length to the byte count for UTF-8 encoded strings.' do
122
+ @unicode_string.encoding.should == Encoding.find("UTF-8")
123
+ ss = SecureString.new(@unicode_string)
124
+ ss.length.should < ss.bytesize
125
+ end
117
126
 
118
- it 'should allow forced transcoding to binary' do
119
- ss = SecureString.new(@unicode_string)
127
+ it 'should allow forced transcoding to binary' do
128
+ ss = SecureString.new(@unicode_string)
120
129
 
121
- ss.encoding.should == Encoding.find("UTF-8")
122
- ss.force_encoding("Binary")
123
- ss.encoding.should == Encoding.find("ASCII-8BIT")
124
- @unicode_string.encoding.should == Encoding.find("UTF-8")
125
- end
130
+ ss.encoding.should == Encoding.find("UTF-8")
131
+ ss.force_encoding("Binary")
132
+ ss.encoding.should == Encoding.find("ASCII-8BIT")
133
+ @unicode_string.encoding.should == Encoding.find("UTF-8")
134
+ end
126
135
 
136
+ end
127
137
  end
128
138
 
129
139
  end
data/spec/spec_helper.rb CHANGED
@@ -8,14 +8,16 @@ MESSAGES = [
8
8
  :string => "Hello",
9
9
  :hex => "48656c6c6f",
10
10
  :int => 310939249775,
11
- :base64 => "SGVsbG8=" # Leave off the \n on purpose so that we can make sure it handles that case appropriately when instantiating using base64.
11
+ :base64 => "SGVsbG8=", # Leave off the \n on purpose so that we can make sure it handles that case appropriately when instantiating using base64.
12
+ :urlsafe_base64 => "SGVsbG8="
12
13
  },
13
14
 
14
15
  {
15
16
  :string => "This is a test of the emergency broadcast system; this is only a test.",
16
17
  :hex => "5468697320697320612074657374206f662074686520656d657267656e63792062726f6164636173742073797374656d3b2074686973206973206f6e6c79206120746573742e",
17
18
  :int => 1244344095146357680190496293767338268850834164562379171846588371816488740307922111470765515885864931093899586331709567338989540039042962957732585272476408412061178229806,
18
- :base64 => "VGhpcyBpcyBhIHRlc3Qgb2YgdGhlIGVtZXJnZW5jeSBicm9hZGNhc3Qgc3lz\ndGVtOyB0aGlzIGlzIG9ubHkgYSB0ZXN0Lg==\n"
19
+ :base64 => "VGhpcyBpcyBhIHRlc3Qgb2YgdGhlIGVtZXJnZW5jeSBicm9hZGNhc3Qgc3lz\ndGVtOyB0aGlzIGlzIG9ubHkgYSB0ZXN0Lg==\n",
20
+ :urlsafe_base64 => "VGhpcyBpcyBhIHRlc3Qgb2YgdGhlIGVtZXJnZW5jeSBicm9hZGNhc3Qgc3lzdGVtOyB0aGlzIGlzIG9ubHkgYSB0ZXN0Lg=="
19
21
  },
20
22
 
21
23
  # This one tests a special case where url safe encodes differently than the standard.
@@ -23,6 +25,7 @@ MESSAGES = [
23
25
  :string => "HI?",
24
26
  :hex => "48493f",
25
27
  :int => 4737343,
26
- :base64 => "SEk/\n"
28
+ :base64 => "SEk/\n",
29
+ :urlsafe_base64 => "SEk_"
27
30
  }
28
31
  ].freeze
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: secure_string
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.2.1
5
+ version: 1.3.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jeff Reinecke
@@ -55,7 +55,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
55
55
  requirements:
56
56
  - - ">="
57
57
  - !ruby/object:Gem::Version
58
- version: 1.9.0
58
+ version: 1.8.6
59
59
  required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  none: false
61
61
  requirements: