lib/stribog/digest.rb in stribog-0.1.3 vs lib/stribog/digest.rb in stribog-0.2.0
- old
+ new
@@ -1,5 +1,7 @@
+require 'base64'
+
module Stribog
# Digest
#
# Class, returning by CreateHash#call
# Contains binary and hex representation of digest.
@@ -10,20 +12,33 @@
#
# @api public
# @example
# digest.binary
# @return [Array] binary representation of digest
- attr_reader :binary
+ attr_reader :vector
+ attr_reader :dec
# Contains hex value of hash
#
# @api public
# @example
# digest.hex
# @return [String] hex representation of digest
- attr_reader :hex
- def initialize(binary_vector:)
- @binary = binary_vector.vector
- @hex = binary_vector.to_hex
+ def initialize(vector:)
+ @vector = vector
+ @dec = vector.to_dec
+ end
+
+ def hex
+ dec.to_s(16)
+ end
+ alias to_hex hex
+
+ def base64
+ Base64.encode64(dec.to_s)
+ end
+
+ def pack(meaning = 'C*')
+ binary.to_byte_array.pack(meaning)
end
end
end