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(value, opts = {}) ⇒ 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_escaped_hex ⇒ Object
Add a method to convert the internal binary dat into an escaped hex string which is suitable for pasting into Ruby and Javascript source files.
-
#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(value, opts = {}) ⇒ 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.
To specify a value kind, pass the :type option.
16 17 18 19 20 |
# File 'lib/secure_string.rb', line 16 def initialize(value, opts={}) 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) data_string = self.class.parse_data(value, opts) 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.
41 42 43 |
# File 'lib/secure_string.rb', line 41 def inspect return "<#{to_hex}>" end |
#to_escaped_hex ⇒ Object
Add a method to convert the internal binary dat into an escaped hex string which is suitable for pasting into Ruby and Javascript source files.
35 36 37 |
# File 'lib/secure_string.rb', line 35 def to_escaped_hex return data_to_escaped_hex end |
#to_hex ⇒ Object
Add a method to convert the internal binary data into a hex string.
29 30 31 |
# File 'lib/secure_string.rb', line 29 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.
24 25 26 |
# File 'lib/secure_string.rb', line 24 def to_i return data_to_i end |