template class Poco::HMACEngine

Overview

This class implementes the HMAC message authentication code algorithm, as specified in RFC 2104. Moreā€¦

#include <HMACEngine.h>

template <class Engine>
class HMACEngine: public Poco::DigestEngine
{
public:
    // enums

    enum
    {
        BLOCK_SIZE  = Engine::BLOCK_SIZE,
        DIGEST_SIZE = Engine::DIGEST_SIZE,
    };

    // construction

    HMACEngine(const std::string& passphrase);

    HMACEngine(
        const char* passphrase,
        std::size_t length
        );

    // methods

    virtual
    std::size_t
    digestLength() const;

    virtual
    void
    reset();

    virtual
    const DigestEngine::Digest&
    digest();

protected:
    // methods

    void
    init(
        const char* passphrase,
        std::size_t length
        );

    virtual
    void
    updateImpl(
        const void* data,
        std::size_t length
        );
};

Inherited Members

public:
    // typedefs

    typedef std::vector<unsigned char> Digest;

    // methods

    void
    update(
        const void* data,
        std::size_t length
        );

    void
    update(char data);

    void
    update(const std::string& data);

    virtual
    std::size_t
    digestLength() const = 0;

    virtual
    void
    reset() = 0;

    virtual
    const Digest&
    digest() = 0;

    static
    std::string
    digestToHex(const Digest& bytes);

    static
    Digest
    digestFromHex(const std::string& digest);

protected:
    // methods

    virtual
    void
    updateImpl(
        const void* data,
        std::size_t length
        ) = 0;

Detailed Documentation

This class implementes the HMAC message authentication code algorithm, as specified in RFC 2104.

The underlying DigestEngine (MD5Engine, SHA1Engine, etc.) must be given as template argument. Since the HMACEngine is a DigestEngine, it can be used with the DigestStream class to create a HMAC for a stream.

Methods

virtual
std::size_t
digestLength() const

Returns the length of the digest in bytes.

virtual
void
reset()

Resets the engine so that a new digest can be computed.

virtual
const DigestEngine::Digest&
digest()

Finishes the computation of the digest and returns the message digest.

Resets the engine and can thus only be called once for every digest. The returned reference is valid until the next time digest() is called, or the engine object is destroyed.

virtual
void
updateImpl(
    const void* data,
    std::size_t length
    )

Updates the digest with the given data.

Must be implemented by subclasses.