Coverage Report

Created: 2024-10-22 12:33

/build/source/nativelink-store/src/cas_utils.rs
Line
Count
Source
1
// Copyright 2024 The NativeLink Authors. All rights reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//    http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
use nativelink_util::common::DigestInfo;
16
use nativelink_util::store_trait::StoreKey;
17
18
pub const ZERO_BYTE_DIGESTS: [DigestInfo; 2] = [
19
    // Sha256 hash of zero bytes.
20
    DigestInfo::new(
21
        [
22
            0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f,
23
            0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b,
24
            0x78, 0x52, 0xb8, 0x55,
25
        ],
26
        0,
27
    ),
28
    // Blake3 hash of zero bytes.
29
    DigestInfo::new(
30
        [
31
            0xaf, 0x13, 0x49, 0xb9, 0xf5, 0xf9, 0xa1, 0xa6, 0xa0, 0x40, 0x4d, 0xea, 0x36, 0xdc,
32
            0xc9, 0x49, 0x9b, 0xcb, 0x25, 0xc9, 0xad, 0xc1, 0x12, 0xb7, 0xcc, 0x9a, 0x93, 0xca,
33
            0xe4, 0x1f, 0x32, 0x62,
34
        ],
35
        0,
36
    ),
37
];
38
39
#[inline]
40
5.99k
pub fn is_zero_digest<'a>(digest: impl Into<StoreKey<'a>>) -> bool {
41
5.99k
    match digest.into() {
42
5.99k
        StoreKey::Digest(digest) => digest.size_bytes() == 0 && 
ZERO_BYTE_DIGESTS.contains(&digest)67
,
  Branch (42:37): [True: 0, False: 0]
  Branch (42:37): [True: 0, False: 0]
  Branch (42:37): [True: 53, False: 5.87k]
  Branch (42:37): [True: 2, False: 2]
  Branch (42:37): [True: 1, False: 6]
  Branch (42:37): [True: 2, False: 2]
  Branch (42:37): [True: 0, False: 0]
  Branch (42:37): [True: 0, False: 0]
  Branch (42:37): [Folded - Ignored]
  Branch (42:37): [True: 7, False: 20]
  Branch (42:37): [True: 0, False: 13]
  Branch (42:37): [True: 2, False: 9]
43
6
        StoreKey::Str(_) => false,
44
    }
45
5.99k
}