Class: Browser::Crypto::Digest

Inherits:
Object
  • Object
show all
Defined in:
opal/browser/crypto.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bufferObject (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_b64Object

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_hexObject

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_sObject

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