Skip to content

Commit e7caa7d

Browse files
akzhanMartin Verzilli
authored and
Martin Verzilli
committedJun 2, 2017
Documentation for OpenSSL::HMAC class. (#4434)
1 parent b8f1504 commit e7caa7d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
 

Diff for: ‎src/openssl/hmac.cr

+26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
require "./lib_crypto"
22

3+
# Allows computing Hash-based Message Authentication Code (HMAC).
4+
#
5+
# It is a type of message authentication code (MAC)
6+
# involving a hash function in combination with a key.
7+
#
8+
# HMAC can be used to verify the integrity of a message as well as the authenticity.
9+
#
10+
# See also [RFC2104](https://tools.ietf.org/html/rfc2104.html).
311
class OpenSSL::HMAC
12+
# Returns the HMAC digest of *data* using the secret *key*.
13+
#
14+
# It may contain non-ASCII bytes, including NUL bytes.
15+
#
16+
# *algorithm* is a `Symbol` of a supported digest algorithm:
17+
# * `:md4`.
18+
# * `:md5`.
19+
# * `:ripemd160`.
20+
# * `:sha1`.
21+
# * `:sha224`.
22+
# * `:sha256`.
23+
# * `:sha384`.
24+
# * `:sha512`.
425
def self.digest(algorithm : Symbol, key, data) : Bytes
526
evp = case algorithm
627
when :md4 then LibCrypto.evp_md4
@@ -20,6 +41,11 @@ class OpenSSL::HMAC
2041
buffer[0, buffer_len.to_i]
2142
end
2243

44+
# Returns the HMAC digest of *data* using the secret *key*,
45+
# formatted as a hexadecimal string. This is neccesary to safely transfer
46+
# the digest where binary messages are not allowed.
47+
#
48+
# See also `#digest`.
2349
def self.hexdigest(algorithm : Symbol, key, data) : String
2450
digest(algorithm, key, data).hexstring
2551
end

0 commit comments

Comments
 (0)
Please sign in to comment.