Class: CryptBuffer
- Inherits:
-
Object
- Object
- CryptBuffer
- Extended by:
- Forwardable
- Includes:
- CryptBufferConcern::Arithmetic, CryptBufferConcern::ByteExpander, CryptBufferConcern::Comparable, CryptBufferConcern::Convertable, CryptBufferConcern::Padding, CryptBufferConcern::PrettyPrint, CryptBufferConcern::Random, CryptBufferConcern::Xor, Enumerable
- Defined in:
- lib/crypto-toolbox/crypt_buffer.rb
Defined Under Namespace
Classes: OutOfRangeError
Instance Attribute Summary collapse
-
#bytes ⇒ Object
(also: #b)
Returns the value of attribute bytes.
Class Method Summary collapse
-
.from_hex(input) ⇒ Object
Make sure input strings are always interpreted as hex strings This is especially useful for unknown or uncertain inputs like strings with or without leading 0x.
Instance Method Summary collapse
- #chunks_of(n) ⇒ Object
-
#initialize(input) ⇒ CryptBuffer
constructor
A new instance of CryptBuffer.
-
#nth_bits(n) ⇒ Object
Returns an array of the nth least sigificant by bit of each byte.
Methods included from CryptBufferConcern::Xor
#xor, #xor_all_with, #xor_at, #xor_space
Methods included from CryptBufferConcern::Random
Methods included from CryptBufferConcern::PrettyPrint
Methods included from CryptBufferConcern::Padding
#pad, #padding, #padding?, #strip_padding
Methods included from CryptBufferConcern::Comparable
Methods included from CryptBufferConcern::Convertable
#bits, #chars, #hex, #str, #to_s
Methods included from CryptBufferConcern::Arithmetic
#add, #mod_sub, #modulus, #sub
Constructor Details
#initialize(input) ⇒ CryptBuffer
Returns a new instance of CryptBuffer.
38 39 40 |
# File 'lib/crypto-toolbox/crypt_buffer.rb', line 38 def initialize(input) @bytes = bytes_from_any(input) end |
Instance Attribute Details
#bytes ⇒ Object Also known as: b
Returns the value of attribute bytes.
32 33 34 |
# File 'lib/crypto-toolbox/crypt_buffer.rb', line 32 def bytes @bytes end |
Class Method Details
.from_hex(input) ⇒ Object
Make sure input strings are always interpreted as hex strings This is especially useful for unknown or uncertain inputs like strings with or without leading 0x
45 46 47 48 49 50 51 |
# File 'lib/crypto-toolbox/crypt_buffer.rb', line 45 def self.from_hex(input) hexstr ="" unless input.nil? hexstr = (input =~ /^0x/ ? input : "0x#{pad_hex_char(input)}" ) end CryptBuffer.new(hexstr) end |
Instance Method Details
#chunks_of(n) ⇒ Object
61 62 63 |
# File 'lib/crypto-toolbox/crypt_buffer.rb', line 61 def chunks_of(n) self.bytes.each_slice(n).map{|chunk| CryptBuffer(chunk) } end |
#nth_bits(n) ⇒ Object
Returns an array of the nth least sigificant by bit of each byte
54 55 56 57 58 59 |
# File 'lib/crypto-toolbox/crypt_buffer.rb', line 54 def nth_bits(n) raise OutOfRangeError if n < 0 raise OutOfRangeError if n > 7 bits.map{|b| b.reverse[n].to_i } end |