Coverage Report

Created: 2025-03-10 17:42

/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
72
Md5Digest::Md5Digest() {
23
72
    MD5_Init(&_md5_ctx);
24
72
}
25
26
104
void Md5Digest::update(const void* data, size_t length) {
27
104
    MD5_Update(&_md5_ctx, data, length);
28
104
}
29
30
72
void Md5Digest::digest() {
31
72
    unsigned char buf[MD5_DIGEST_LENGTH];
32
72
    MD5_Final(buf, &_md5_ctx);
33
34
72
    char hex_buf[2 * MD5_DIGEST_LENGTH];
35
36
72
    static char dig_vec_lower[] = "0123456789abcdef";
37
72
    char* to = hex_buf;
38
1.22k
    for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) {
39
1.15k
        *to++ = dig_vec_lower[buf[i] >> 4];
40
1.15k
        *to++ = dig_vec_lower[buf[i] & 0x0F];
41
1.15k
    }
42
72
    _hex.assign(hex_buf, 2 * MD5_DIGEST_LENGTH);
43
72
}
44
45
} // namespace doris