diff options
Diffstat (limited to 'src/common/mac')
-rw-r--r-- | src/common/mac/file_id.cc | 8 | ||||
-rw-r--r-- | src/common/mac/macho_id.cc | 36 | ||||
-rw-r--r-- | src/common/mac/macho_id.h | 19 |
3 files changed, 14 insertions, 49 deletions
diff --git a/src/common/mac/file_id.cc b/src/common/mac/file_id.cc index ebb8c40e..50502e4c 100644 --- a/src/common/mac/file_id.cc +++ b/src/common/mac/file_id.cc @@ -53,19 +53,19 @@ bool FileID::FileIdentifier(unsigned char identifier[16]) { if (fd == -1) return false; - MD5_CTX md5; - MD5_Init(&md5); + MD5Context md5; + MD5Init(&md5); // Read 4k x 2 bytes at a time. This is faster than just 4k bytes, but // doesn't seem to be an unreasonable size for the stack. unsigned char buffer[4096 * 2]; size_t buffer_size = sizeof(buffer); while ((buffer_size = read(fd, buffer, buffer_size) > 0)) { - MD5_Update(&md5, buffer, buffer_size); + MD5Update(&md5, buffer, buffer_size); } close(fd); - MD5_Final(identifier, &md5); + MD5Final(identifier, &md5); return true; } diff --git a/src/common/mac/macho_id.cc b/src/common/mac/macho_id.cc index 486cf536..44e78205 100644 --- a/src/common/mac/macho_id.cc +++ b/src/common/mac/macho_id.cc @@ -37,8 +37,6 @@ extern "C" { // necessary for Leopard #include <fcntl.h> #include <mach-o/loader.h> #include <mach-o/swap.h> - #include <openssl/md5.h> - #include <openssl/sha.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -57,7 +55,6 @@ MachoID::MachoID(const char *path) : file_(0), crc_(0), md5_context_(), - sha1_context_(), update_function_(NULL) { strlcpy(path_, path, sizeof(path_)); file_ = open(path, O_RDONLY); @@ -117,11 +114,7 @@ void MachoID::UpdateCRC(unsigned char *bytes, size_t size) { } void MachoID::UpdateMD5(unsigned char *bytes, size_t size) { - MD5_Update(&md5_context_, bytes, size); -} - -void MachoID::UpdateSHA1(unsigned char *bytes, size_t size) { - SHA_Update(&sha1_context_, bytes, size); + MD5Update(&md5_context_, bytes, size); } void MachoID::Update(MachoWalker *walker, off_t offset, size_t size) { @@ -225,30 +218,13 @@ bool MachoID::MD5(int cpu_type, unsigned char identifier[16]) { MachoWalker walker(path_, WalkerCB, this); update_function_ = &MachoID::UpdateMD5; - if (MD5_Init(&md5_context_)) { - if (!walker.WalkHeader(cpu_type)) - return false; - - MD5_Final(identifier, &md5_context_); - return true; - } - - return false; -} + MD5Init(&md5_context_); -bool MachoID::SHA1(int cpu_type, unsigned char identifier[16]) { - MachoWalker walker(path_, WalkerCB, this); - update_function_ = &MachoID::UpdateSHA1; - - if (SHA_Init(&sha1_context_)) { - if (!walker.WalkHeader(cpu_type)) - return false; - - SHA_Final(identifier, &sha1_context_); - return true; - } + if (!walker.WalkHeader(cpu_type)) + return false; - return false; + MD5Final(identifier, &md5_context_); + return true; } // static diff --git a/src/common/mac/macho_id.h b/src/common/mac/macho_id.h index ea01a6d7..9bcefc56 100644 --- a/src/common/mac/macho_id.h +++ b/src/common/mac/macho_id.h @@ -36,8 +36,8 @@ #include <limits.h> #include <mach-o/loader.h> -#include <openssl/md5.h> -#include <openssl/sha.h> + +#include "common/md5.h" namespace MacFileUtilities { @@ -65,10 +65,6 @@ class MachoID { // Return true on success, false otherwise bool MD5(int cpu_type, unsigned char identifier[16]); - // For the given |cpu_type|, return the SHA1 for the mach-o data segment(s). - // Return true on success, false otherwise - bool SHA1(int cpu_type, unsigned char identifier[16]); - private: // Signature of class member function to be called with data read from file typedef void (MachoID::*UpdateFunction)(unsigned char *bytes, size_t size); @@ -81,14 +77,10 @@ class MachoID { // to each byte. void UpdateMD5(unsigned char *bytes, size_t size); - // Update the SHA1 value by examining |size| |bytes| and applying the - // algorithm to each byte. - void UpdateSHA1(unsigned char *bytes, size_t size); - // Bottleneck for update routines void Update(MachoWalker *walker, off_t offset, size_t size); - // The callback from the MachoWalker for CRC, MD5, and SHA1 + // The callback from the MachoWalker for CRC and MD5 static bool WalkerCB(MachoWalker *walker, load_command *cmd, off_t offset, bool swap, void *context); @@ -110,10 +102,7 @@ class MachoID { uint32_t crc_; // The MD5 context - MD5_CTX md5_context_; - - // The SHA1 context - SHA_CTX sha1_context_; + MD5Context md5_context_; // The current update to call from the Update callback UpdateFunction update_function_; |