Class: Browser::Crypto::Digest
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
Instance Method Summary collapse
-
#initialize(buf) ⇒ Digest
constructor
A new instance of Digest.
-
#to_b64 ⇒ Object
Convert a digest to a Base64-encoded string.
-
#to_hex ⇒ Object
Convert a digest to a hexadecimal string.
-
#to_s ⇒ Object
Convert a digest to a binary string.
-
#to_u64(padding: false) ⇒ Object
Convert a digest to a urlsafe Base64-encoded string.
Constructor Details
#initialize(buf) ⇒ Digest
Returns a new instance of Digest.
11 12 13 |
# File 'opal/browser/crypto.rb', line 11 def initialize(buf) @buffer = Buffer.new(buf) end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
15 16 17 |
# File 'opal/browser/crypto.rb', line 15 def buffer @buffer end |
Instance Method Details
#to_b64 ⇒ Object
Convert a digest to a Base64-encoded string
You will need to require "base64"
30 31 32 |
# File 'opal/browser/crypto.rb', line 30 def to_b64 Base64.strict_encode64(to_s) end |
#to_hex ⇒ Object
Convert a digest to a hexadecimal string
18 19 20 |
# File 'opal/browser/crypto.rb', line 18 def to_hex buffer.to_a.map { |i| "%02x" % i }.join end |
#to_s ⇒ Object
Convert a digest to a binary string
23 24 25 |
# File 'opal/browser/crypto.rb', line 23 def to_s buffer.to_a.map { |i| "%c" % i }.join end |
#to_u64(padding: false) ⇒ Object
Convert a digest to a urlsafe Base64-encoded string
You will need to require "base64"
37 38 39 |
# File 'opal/browser/crypto.rb', line 37 def to_u64(padding: false) Base64.urlsafe_encode64(to_s, padding: padding) end |