`hashlib` add Protocol for hash-objects
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 36k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Feature or enhancement
hashlib describes a Protocol for hash objects without implementing it.
The proposal is simply to create a concreate Hash or HashObject protocol that makes it explicit.
Pitch
Using the Buffer Protocol (PEP 688) this should look something like
@runtime_checkable
class Hash(Protocol):
name: str
def digest_size(self) -> int:
"""Return the size of the hash in bytes."""
def block_size(self) -> int:
"""Return the internal block size of the hash in bytes."""
def update(self, data: Buffer) -> None:
"""Update this hash object's state with the provided string."""
def digest(self) -> bytes:
"""Return the digest value as a string of binary data."""
def hexdigest(self) -> str:
"""Return the digest value as a string of hexadecimal digits."""
def copy(self) -> Self:
"""Return a copy ("clone") of the hash object."""
Having a Protocol class instead of prose makes it clear how exactly a hash-function needs to look like.
A second suggestion would be to change hashlib.algorithms_guaranteed and hashlib.algorithms_available from set[str] to dict[str, type[Hash]] objects.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginnen Sie mit der hashlib-Dokumentation und dem referenzierten PEP 688 Buffer Protocol, um die vorgeschlagene Hash-Schnittstelle mit bestehenden Hash-Objekten zu vergleichen. Klären Sie, ob ein zur Laufzeit prüfbares Protocol hinzugefügt werden sollte und ob algorithms_guaranteed und algorithms_available von Mengen in Mappings geändert werden sollten. Erledigt bedeutet, dass die akzeptierte API spezifiziert und mit geeigneter Abdeckung für die unterstützten Hash-Objekte implementiert ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- cryptography
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100