1 /* 2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef LIBGAV1_TESTS_THIRD_PARTY_LIBVPX_MD5_HELPER_H_ 12 #define LIBGAV1_TESTS_THIRD_PARTY_LIBVPX_MD5_HELPER_H_ 13 14 #include <cstddef> 15 #include <cstdint> 16 17 #include "tests/third_party/libvpx/md5_utils.h" 18 19 namespace libvpx_test { 20 class MD5 { 21 public: MD5()22 MD5() { MD5Init(&md5_); } 23 Add(const uint8_t * data,size_t size)24 void Add(const uint8_t *data, size_t size) { 25 MD5Update(&md5_, data, static_cast<uint32_t>(size)); 26 } 27 Get(void)28 const char *Get(void) { 29 static const char hex[16] = { 30 '0', '1', '2', '3', '4', '5', '6', '7', 31 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 32 }; 33 uint8_t tmp[16]; 34 MD5Context ctx_tmp = md5_; 35 36 MD5Final(tmp, &ctx_tmp); 37 for (int i = 0; i < 16; i++) { 38 res_[i * 2 + 0] = hex[tmp[i] >> 4]; 39 res_[i * 2 + 1] = hex[tmp[i] & 0xf]; 40 } 41 res_[32] = 0; 42 43 return res_; 44 } 45 46 protected: 47 char res_[33]; 48 MD5Context md5_; 49 }; 50 51 } // namespace libvpx_test 52 53 #endif // LIBGAV1_TESTS_THIRD_PARTY_LIBVPX_MD5_HELPER_H_ 54