feat/add digest calculate
This commit is contained in:
parent
a379706f78
commit
ec099b76ec
1 changed files with 26 additions and 0 deletions
26
app/httpsig.py
Normal file
26
app/httpsig.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env python3
|
||||
import base64
|
||||
from typing import Literal, TypedDict, cast, Any
|
||||
|
||||
from Crypto.Hash import SHA256
|
||||
from Crypto.Signature import PKCS1_v1_5
|
||||
|
||||
class HttpSignature:
|
||||
"""
|
||||
calculation and verification of HTTP signatures
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def calculation_digest(cls,
|
||||
body: bytes,
|
||||
algorithm="sha-256")-> str :
|
||||
"""
|
||||
Calculates the digest header value for a given HTTP body
|
||||
"""
|
||||
if "sha-256" == algorithm:
|
||||
h = SHA256.new()
|
||||
h.update(body)
|
||||
return "SHA-256=" + \
|
||||
base64.b64encode(h.digest()).decode("utf-8")
|
||||
else:
|
||||
raise ValueError(f"Not support algorithm {algorithm}")
|
Loading…
Reference in a new issue