Make the encoding API more type-safe
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- rust
- Área
- authentication, security
Línea de trabajo
El issue identifica Header, EncodingKey y encode como la API afectada; empieza por localizar sus definiciones y el algoritmo actual en tiempo de ejecución y las comprobaciones de claves. Se considera terminado cuando las familias de algoritmos incompatibles se rechacen en tiempo de compilación, mientras la API genérica propuesta siga siendo utilizable para los flujos de encoding compatibles.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Hi!
The current API allows writing encoding code with a key that does not match the algorithm used, e.g.
let header = Header { alg: Algorithm::RS256, ..Default::default() };
let encoding_key = EncodingKey::from_secret("shared_secret".as_bytes());
let token = encode(&header, &claims, &encoding_key);
This results in an error because the key type does not match the algorithm family.
This kind of error could be caught at compile time.
My proposal is to change the crate's API to catch this kind of error at compile-time instead of runtime, by moving from an enum-based checking to a type-based system.
Here is an overview of the proposed changes:
- Each algorithm family becomes a separated
enum. - the
Headerstruct is changed toHeader<AF>, taking its algorithm family enum as type parameter, with analgorithm: AFdata member. - similarly, the
EncodingKeystruct is changed toEncodingKey<AF>, withAFrecorded in aPhantomDatamember. - the
encodefunction's signature is changed to something like
pub fn encode<T: Serialize, AF>(header: &Header<AF>, claims: &T, key: &EncodingKey<AF>) -> Result<String>
With this approach, code using a key for the wrong algorithm family will no longer compile, and we can get rid of some runtime checks.
On the other hand, you can no longer implement FromStr for all algorithms families at once. But since one needs to call a different function to generate the key depending on the algorithm family, I don't think this is a huge problem.
Would you be interested in a PR implementing this proposal?
- Lenguaje dominante
- Rust
- Estrellas
- 2.1k
- Forks
- 375
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Keats/jsonwebtoken
-
rust_crypto EdDSA verifier panics on short public keys and truncates long onesPosiblemente ocupada @akashchamp la tomó hace 7 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Keats/jsonwebtoken#547 ·
-
`Jwk::from_encoding_key` rejects PKCS#8 v2 (RFC 5958) Ed25519 private keysPosiblemente ocupada @ucsurf la tomó hace 29 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Keats/jsonwebtoken#544 · 1 comentario ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
Keats/jsonwebtoken#542 · 1 comentario ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Keats/jsonwebtoken#519 · 2 comentarios ·
-
Incorrect behavior when using `from_ec_der` with `rust-crypto` providerPosiblemente ocupada @mamicicekel la tomó hace 4 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Keats/jsonwebtoken#497 ·
Todos los issues de Keats/jsonwebtoken
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
longbridge/nsh#804 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
devex good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
calcit-lang/calcit#2538 ·
Los mantenedores suelen responder en 1 día