blob: 256d037120190b7f1982540bc7993fd94e16d0fd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# SPDX-FileCopyrightText: 2026 Dennis Fink <me+coding@dennisfink.me>
#
# SPDX-License-Identifier: BSD-3-Clause
"""Portable SHA-256 fingerprints for indexed Webmention URLs."""
import hashlib
import json
def received_url_digest(source: str, target: str) -> str:
"""Fingerprint an unambiguous, ordered source/target pair."""
encoded = json.dumps(
[source, target], ensure_ascii=False, separators=(",", ":")
).encode("utf-8")
return hashlib.sha256(encoded).hexdigest()
def sent_target_digest(target: str) -> str:
"""Fingerprint an outgoing target (unique within each source ID)."""
return hashlib.sha256(target.encode("utf-8")).hexdigest()
|