Class: SecureString
- Inherits:
-
String
- Object
- String
- SecureString
- Includes:
- SecurizeString
- Defined in:
- lib/secure_string.rb
Overview
SecureString is a String subclass whose emphasis is on byte data rather than human readable strings. class gives a number of conveniences, such as easier viewing of the byte data as hex, digest methods, and encryption and decryption methods.
Instance Method Summary collapse
-
#initialize(mode = :data, value) ⇒ SecureString
constructor
Creates the string from one many kinds of values: [:data] (default) The passed string value is directly used.
-
#inspect ⇒ Object
Override the default inspect to return the hexidecimal representation of the data contained in this string.
-
#to_hex ⇒ Object
Add a method to convert the internal binary data into a hex string.
-
#to_i ⇒ Object
Override the default to_i method to return the integer value of the data contained in the string, rather than the parsed value of the characters.
Methods included from SecurizeString
Constructor Details
#initialize(mode = :data, value) ⇒ SecureString
Creates the string from one many kinds of values:
- :data
-
(default) The passed string value is directly used.
- :hex
-
Initialize using a hexidecimal string.
- :int
-
Initialize using the numeric value of the hexidecimal string.
- :base64
-
Initialize using the given base64 encoded data.
15 16 17 18 |
# File 'lib/secure_string.rb', line 15 def initialize(mode = :data, value) data_string = self.class.parse_data(mode, value) self.replace( data_string ) end |
Instance Method Details
#inspect ⇒ Object
Override the default inspect to return the hexidecimal representation of the data contained in this string.
33 34 35 |
# File 'lib/secure_string.rb', line 33 def inspect return "<#{to_hex}>" end |
#to_hex ⇒ Object
Add a method to convert the internal binary data into a hex string.
27 28 29 |
# File 'lib/secure_string.rb', line 27 def to_hex return data_to_hex end |
#to_i ⇒ Object
Override the default to_i method to return the integer value of the data contained in the string, rather than the parsed value of the characters.
22 23 24 |
# File 'lib/secure_string.rb', line 22 def to_i return data_to_i end |