Add md5 type checksum type.
This commit is contained in:
parent
f7151eba30
commit
dd4c963667
2 changed files with 28 additions and 0 deletions
|
@ -3,8 +3,10 @@ from typing import Dict, Optional, Type
|
|||
from fck.cktype.cktypeinterface import CKTYPEINTERFACE as CKTYPEINTERFACE
|
||||
|
||||
from .crc32 import CRC32
|
||||
from .md5 import MD5
|
||||
|
||||
CKTYPES: Dict[str, Type[MD5 | CRC32]] = {
|
||||
"MD5": (MD5),
|
||||
"CRC32": (CRC32),
|
||||
}
|
||||
|
||||
|
|
26
fck/cktype/md5.py
Normal file
26
fck/cktype/md5.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
from typing import List
|
||||
from re import compile, Pattern
|
||||
from hashlib import md5
|
||||
|
||||
|
||||
class MD5(object):
|
||||
NAME: str = "MD5"
|
||||
EXT: List[str] = [".md5"]
|
||||
SYNTAX: List[Pattern] = [compile(r"^;*$"), compile(r"^.* [0-9a-fA-F]{8}$")]
|
||||
REGEX: Pattern = compile(r"[0-9a-fA-F]{32}")
|
||||
NULL: str = "D41D8CD98F00B204E9800998ECF8427E"
|
||||
|
||||
def __init__(self):
|
||||
self.cksum = md5(usedforsecurity=False)
|
||||
|
||||
def gensum(self, data: bytes):
|
||||
self.cksum.update(data)
|
||||
|
||||
def reset(self):
|
||||
self.__init__()
|
||||
|
||||
def format(self, fpath) -> str:
|
||||
return " ".join([self.__repr__(), fpath])
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return self.cksum.hexdigest().upper()
|
Loading…
Reference in a new issue