00001 /* 00002 * Copyright 2004-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 00018 #ifndef _OASYS_MD5_H_ 00019 #define _OASYS_MD5_H_ 00020 00021 #include <sys/types.h> 00022 #include <string> 00023 00024 #include "StringUtils.h" 00025 #include "../serialize/Serialize.h" 00026 00027 extern "C" { 00028 #define PROTOTYPES 1 00029 #include "md5-rsa.h" 00030 } 00031 00032 namespace oasys { 00036 class MD5 { 00037 public: 00038 static const unsigned int MD5LEN = 16; 00039 00040 MD5(); 00041 ~MD5() {} 00042 00044 void init(); 00045 00047 void update(const u_char* data, size_t len); 00048 00050 void update(const char* data, size_t len); 00051 00053 void finalize(); 00054 00056 const u_char* digest(); 00057 00059 static void digest_ascii(std::string* str, const u_char* digest); 00060 00062 static std::string digest_ascii(const u_char* digest); 00063 00065 void digest_ascii(std::string* str); 00066 00068 std::string digest_ascii(); 00069 00071 static void digest_fromascii(const char* str, u_char* digest); 00072 00073 private: 00074 MD5_CTX ctx_; 00075 u_char digest_[MD5LEN]; 00076 }; 00077 00081 struct MD5Hash_t : public SerializableObject { 00082 u_char hash_[MD5::MD5LEN]; 00083 00084 MD5Hash_t& operator=(const MD5Hash_t& hash); 00085 00086 // virtual from SerializableObject 00087 void serialize(SerializeAction* a); 00088 }; 00089 00090 } // namespace oasys 00091 00092 #endif /* _OASYS_MD5_H_ */