`hashlib` add Protocol for hash-objects
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 36k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con la documentazione di hashlib e con il PEP 688 Buffer Protocol citato per confrontare l’interfaccia Hash proposta con gli oggetti hash esistenti. Determina se aggiungere un protocollo verificabile a runtime e se algorithms_guaranteed e algorithms_available debbano passare da insiemi a mapping. Il lavoro è completato quando l’API accettata è specificata e implementata con una copertura adeguata per gli oggetti hash supportati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- cryptography
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100