-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdigester.py
38 lines (25 loc) · 1000 Bytes
/
digester.py
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
35
36
37
38
# Copyright (C) 2019-2022 Vanessa Sochat.
# This Source Code Form is subject to the terms of the
# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
# with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
from opencontainers.struct import Struct
from hashlib import new
class Digester(Struct):
"""
Digester calculates the digest of written data.
Writes should go directly to the return value of Hash, while calling Digest
will return the current value of the digest.
"""
def __init__(self):
self.Hash = digester.digest
self.Digest = digester.digest
super().__init__()
class digester(Struct):
"""Digester provides a simple digester definition that embeds a hasher."""
def __init__(self, alg=None, hashObj=None):
super().__init__()
self.alg = alg
self.hash = hashObj
def digest(self):
from .digest import NewDigest
return NewDigest(self.alg, self.hash)