File: HashFunctions.h

package info (click to toggle)
openh264 2.6.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,120 kB
  • sloc: cpp: 74,004; asm: 34,842; ansic: 23,866; sh: 2,540; python: 937; objc: 612; cs: 471; makefile: 354; java: 319; xml: 204; javascript: 17
file content (34 lines) | stat: -rw-r--r-- 1,072 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef __HASHFUNCTIONS_H__
#define __HASHFUNCTIONS_H__

#include <stdio.h>
#include <string.h>
#include <gtest/gtest.h>
#include "../sha1.h"
#include "crt_util_safe_x.h"

static void ToHashStr (char* dst, const unsigned char* src, size_t src_len) {
  for (size_t i = 0; i < src_len; ++i) {
    WelsSnprintf (&dst[i * 2], 3, "%.2x", src[i]);
  }
  dst[src_len * 2] = '\0';
}

inline void CompareHash (const unsigned char* digest, const char* hashStr) {
  char hashStrCmp[SHA_DIGEST_LENGTH * 2 + 1];
  ToHashStr (hashStrCmp, digest, SHA_DIGEST_LENGTH);
  EXPECT_STREQ (hashStr, hashStrCmp);
}

inline void CompareHashAnyOf (const unsigned char* digest, const char* const hashStr[], size_t nHashStr) {
  char hashStrCmp[SHA_DIGEST_LENGTH * 2 + 1];
  ToHashStr (hashStrCmp, digest, SHA_DIGEST_LENGTH);
  for (size_t i = 0; i < nHashStr && hashStr[i]; ++i) {
    if (0 == strcmp (hashStr[i], hashStrCmp))
      return;
  }
  // No match found. Compare to first hash so as to produce a grepable failure.
  EXPECT_STREQ (hashStr[0], hashStrCmp);
}

#endif //__HASHFUNCTIONS_H__