MD5.cc

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2005-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 #include "MD5.h"
00018 
00019 namespace oasys {
00020 
00021 MD5::MD5() 
00022 {
00023     init();
00024 }
00025 
00027 void 
00028 MD5::init()
00029 {
00030     MD5Init(&ctx_);
00031 }
00032     
00034 void 
00035 MD5::update(const u_char* data, size_t len)
00036 {
00037     MD5Update(&ctx_, (u_char*)data, len);
00038 }
00039 
00041 void 
00042 MD5::update(const char* data, size_t len)
00043 {
00044     MD5Update(&ctx_, (u_char*)data, len);
00045 }
00046 
00048 void 
00049 MD5::finalize()
00050 {
00051     MD5Final(digest_, &ctx_);
00052 }
00053 
00055 const u_char* 
00056 MD5::digest()
00057 {
00058     return digest_;
00059 }
00060 
00062 void 
00063 MD5::digest_ascii(std::string* str,
00064                   const u_char* digest)
00065 {
00066     hex2str(str, digest, MD5LEN);
00067 }
00068 
00070 std::string 
00071 MD5::digest_ascii(const u_char* digest)
00072 {
00073     std::string str;
00074     digest_ascii(&str, digest);
00075     return str;
00076 }
00077 
00079 void 
00080 MD5::digest_ascii(std::string* str)
00081 {
00082     digest_ascii(str, digest_);
00083 }
00084 
00086 std::string 
00087 MD5::digest_ascii()
00088 {
00089     return digest_ascii(digest_);
00090 }
00091 
00093 void 
00094 MD5::digest_fromascii(const char* str, u_char* digest)
00095 {
00096     str2hex(str, digest, MD5LEN);
00097 }
00098 
00099 
00100 void 
00101 MD5Hash_t::serialize(SerializeAction* a)
00102 {
00103     a->process("hash", reinterpret_cast<char*>(hash_), MD5::MD5LEN);
00104 }
00105 
00106 MD5Hash_t& 
00107 MD5Hash_t::operator=(const MD5Hash_t& hash)
00108 {
00109     memcpy(hash_, hash.hash_, MD5::MD5LEN);
00110 
00111     return *this;
00112 }
00113 
00114 }; // namespace oasys

Generated on Sat Sep 8 08:43:30 2007 for DTN Reference Implementation by  doxygen 1.5.3