• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include "ChecksumCalculator.h"
20 
21 #include <stdio.h>
22 
23 // NOTE: This fork of ChecksumCalculatorThreadInfo is *not* thread safe
24 
25 class ChecksumCalculatorThreadInfo {
26   public:
writeChecksum(ChecksumCalculator * calc,void * buf,size_t bufLen,void * outputChecksum,size_t outputChecksumLen)27     static bool writeChecksum(ChecksumCalculator* calc, void* buf, size_t bufLen,
28                               void* outputChecksum, size_t outputChecksumLen) {
29         calc->addBuffer(buf, bufLen);
30         return calc->writeChecksum(outputChecksum, outputChecksumLen);
31     }
32 
validate(ChecksumCalculator * calc,void * buf,size_t bufLen,void * checksum,size_t checksumLen)33     static bool validate(ChecksumCalculator* calc, void* buf, size_t bufLen, void* checksum,
34                          size_t checksumLen) {
35         calc->addBuffer(buf, bufLen);
36         return calc->validate(checksum, checksumLen);
37     }
38 
validOrDie(ChecksumCalculator * calc,void * buf,size_t bufLen,void * checksum,size_t checksumLen,const char * message)39     static void validOrDie(ChecksumCalculator* calc, void* buf, size_t bufLen, void* checksum,
40                            size_t checksumLen, const char* message) {
41         if (!validate(calc, buf, bufLen, checksum, checksumLen)) {
42             printf("%s\n", message);
43         }
44     }
45 };
46