class CryptBuffer
Attributes
b[RW]
bytes[RW]
Public Class Methods
from_base64(input)
click to toggle source
# File lib/crypto-toolbox/crypt_buffer.rb, line 54 def self.from_base64(input) CryptBufferInputConverter.new.from_base64(input) end
from_hex(input)
click to toggle source
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
# File lib/crypto-toolbox/crypt_buffer.rb, line 50 def self.from_hex(input) CryptBufferInputConverter.new.from_hex(input) end
new(byte_array)
click to toggle source
# File lib/crypto-toolbox/crypt_buffer.rb, line 43 def initialize(byte_array) @bytes = byte_array end
Public Instance Methods
chunks_of(n)
click to toggle source
# File lib/crypto-toolbox/crypt_buffer.rb, line 73 def chunks_of(n) self.bytes.each_slice(n).map{|chunk| CryptBuffer(chunk) } end
nth_bits(n)
click to toggle source
Returns an array of the nth least sigificant by bit of each byte
# File lib/crypto-toolbox/crypt_buffer.rb, line 66 def nth_bits(n) raise OutOfRangeError if n < 0 raise OutOfRangeError if n > 7 bits.map{|b| b.reverse[n].to_i } end
nth_bytes(n,offset: 0)
click to toggle source
# File lib/crypto-toolbox/crypt_buffer.rb, line 58 def nth_bytes(n,offset: 0) return CryptBuffer([]) if n.nil? || n < 1 CryptBuffer((0+offset).step(length,n).map{|i| bytes[i] }.compact) end