Source

Magnum / source / libs / magnum_crypto / source / magnum / crypto / MD5Digester.cpp

Full commit
/* 
  Magnum 
  Copyright (C) 2002-2011 Kaya Kupferschmidt. All Rights Reserved.

  This software is provided 'as-is', without any express or implied
  warranty.  In no event will the authors be held liable for any damages
  arising from the use of this software.

  Permission is granted to anyone to use this software for any purpose,
  including commercial applications, and to alter it and redistribute it
  freely, under the terms in LICENSE.TXT.

  Kaya Kupferschmidt  (k.kupferschmidt@dimajix.de)
*/

#include "magnum/openssl/OpenSSL.h"
#include "magnum/crypto/MD5Digester.h"


namespace magnum { namespace crypto {
using magnum::openssl::OpenSSL;


/*--------------------------------------------------------------------------*/
/**
 */
MD5Digester::MD5Digester()
: AbstractDigester("MD5")
{
    OpenSSL::startup();
    MD5_Init(&m_Context);
}


/*--------------------------------------------------------------------------*/
/**
 */
MD5Digester::~MD5Digester()
{
}


/*--------------------------------------------------------------------------*/
/**
 */
void MD5Digester::resetImpl()
{
    MD5_Init(&m_Context);
}


/*--------------------------------------------------------------------------*/
/**
 */
void MD5Digester::updateImpl(const void* data, size_t len)
{
    MD5_Update(&m_Context, data, len);
}


/*--------------------------------------------------------------------------*/
/**
 */
ByteArray MD5Digester::digestImpl()
{
    unsigned char buffer[MD5_DIGEST_LENGTH];
    MD5_Final(buffer, &m_Context);
    return ByteArray((char*)buffer, MD5_DIGEST_LENGTH);
}

} }