Copyright | Will Thompson and Iñaki García Etxebarria |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
GI.GLib.Structs.Hmac
Description
HMACs should be used when producing a cookie or hash based on data and a key. Simple mechanisms for using SHA1 and other algorithms to digest a key and data together are vulnerable to various security issues. HMAC uses algorithms like SHA1 in a secure way to produce a digest of a key and data.
Both the key and data are arbitrary byte arrays of bytes or characters.
Support for HMAC Digests has been added in GLib 2.30, and support for SHA-512 in GLib 2.42. Support for SHA-384 was added in GLib 2.52.
To create a new GHmac
, use hmacNew
. To free a GHmac
, use
hmacUnref
.
Since: 2.30
Synopsis
- newtype Hmac = Hmac (ManagedPtr Hmac)
- hmacCopy :: (HasCallStack, MonadIO m) => Hmac -> m Hmac
- hmacGetDigest :: (HasCallStack, MonadIO m) => Hmac -> ByteString -> m ()
- hmacGetString :: (HasCallStack, MonadIO m) => Hmac -> m Text
- hmacNew :: (HasCallStack, MonadIO m) => ChecksumType -> ByteString -> m (Maybe Hmac)
- hmacRef :: (HasCallStack, MonadIO m) => Hmac -> m Hmac
- hmacUnref :: (HasCallStack, MonadIO m) => Hmac -> m ()
- hmacUpdate :: (HasCallStack, MonadIO m) => Hmac -> ByteString -> m ()
Exported types
Memory-managed wrapper type.
Constructors
Hmac (ManagedPtr Hmac) |
Instances
Eq Hmac Source # | |
GBoxed Hmac Source # | |
Defined in GI.GLib.Structs.Hmac | |
ManagedPtrNewtype Hmac Source # | |
Defined in GI.GLib.Structs.Hmac Methods toManagedPtr :: Hmac -> ManagedPtr Hmac Source # | |
TypedObject Hmac Source # | |
HasParentTypes Hmac Source # | |
Defined in GI.GLib.Structs.Hmac | |
IsGValue (Maybe Hmac) Source # | Convert |
type ParentTypes Hmac Source # | |
Defined in GI.GLib.Structs.Hmac |
Methods
Click to display all available methods, including inherited ones
copy
Arguments
:: (HasCallStack, MonadIO m) | |
=> Hmac |
|
-> m Hmac | Returns: the copy of the passed |
Copies a Hmac
. If hmac
has been closed, by calling
hmacGetString
or hmacGetDigest
, the copied
HMAC will be closed as well.
Since: 2.30
getDigest
Arguments
:: (HasCallStack, MonadIO m) | |
=> Hmac |
|
-> ByteString |
|
-> m () |
Gets the digest from checksum
as a raw binary array and places it
into buffer
. The size of the digest depends on the type of checksum.
Once this function has been called, the Hmac
is closed and can
no longer be updated with checksumUpdate
.
Since: 2.30
getString
Arguments
:: (HasCallStack, MonadIO m) | |
=> Hmac |
|
-> m Text | Returns: the hexadecimal representation of the HMAC. The returned string is owned by the HMAC and should not be modified or freed. |
Gets the HMAC as a hexadecimal string.
Once this function has been called the Hmac
can no longer be
updated with hmacUpdate
.
The hexadecimal characters will be lower case.
Since: 2.30
new
Arguments
:: (HasCallStack, MonadIO m) | |
=> ChecksumType |
|
-> ByteString |
|
-> m (Maybe Hmac) | Returns: the newly created |
Creates a new Hmac
, using the digest algorithm digestType
.
If the digestType
is not known, Nothing
is returned.
A Hmac
can be used to compute the HMAC of a key and an
arbitrary binary blob, using different hashing algorithms.
A Hmac
works by feeding a binary blob through hmacUpdate
until the data is complete; the digest can then be extracted
using hmacGetString
, which will return the checksum as a
hexadecimal string; or hmacGetDigest
, which will return a
array of raw bytes. Once either hmacGetString
or
hmacGetDigest
have been called on a Hmac
, the HMAC
will be closed and it won't be possible to call hmacUpdate
on it anymore.
Support for digests of type ChecksumTypeSha512
has been added in GLib 2.42.
Support for ChecksumTypeSha384
was added in GLib 2.52.
Since: 2.30
ref
Arguments
:: (HasCallStack, MonadIO m) | |
=> Hmac |
|
-> m Hmac | Returns: the passed in |
Atomically increments the reference count of hmac
by one.
This function is MT-safe and may be called from any thread.
Since: 2.30
unref
Arguments
:: (HasCallStack, MonadIO m) | |
=> Hmac |
|
-> m () |
Atomically decrements the reference count of hmac
by one.
If the reference count drops to 0, all keys and values will be
destroyed, and all memory allocated by the hash table is released.
This function is MT-safe and may be called from any thread.
Frees the memory allocated for hmac
.
Since: 2.30
update
Arguments
:: (HasCallStack, MonadIO m) | |
=> Hmac |
|
-> ByteString |
|
-> m () |
Feeds data
into an existing Hmac
.
The HMAC must still be open, that is hmacGetString
or
hmacGetDigest
must not have been called on hmac
.
Since: 2.30