Coverage Report

Created: 2024-11-20 15:52

/root/doris/be/src/util/md5.cpp
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#include "util/md5.h"
19
20
namespace doris {
21
22
59
Md5Digest::Md5Digest() {
23
59
    MD5_Init(&_md5_ctx);
24
59
}
25
26
91
void Md5Digest::update(const void* data, size_t length) {
27
91
    MD5_Update(&_md5_ctx, data, length);
28
91
}
29
30
59
void Md5Digest::digest() {
31
59
    unsigned char buf[MD5_DIGEST_LENGTH];
32
59
    MD5_Final(buf, &_md5_ctx);
33
34
59
    char hex_buf[2 * MD5_DIGEST_LENGTH];
35
36
59
    static char dig_vec_lower[] = "0123456789abcdef";
37
59
    char* to = hex_buf;
38
1.00k
    for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) {
39
944
        *to++ = dig_vec_lower[buf[i] >> 4];
40
944
        *to++ = dig_vec_lower[buf[i] & 0x0F];
41
944
    }
42
59
    _hex.assign(hex_buf, 2 * MD5_DIGEST_LENGTH);
43
59
}
44
45
} // namespace doris