Skip to content

Refactor PaddingScheme into a trait - #244

Merged
tarcieri merged 5 commits into
masterfrom
refactor-padding-scheme-into-trait
Jan 10, 2023
Merged

Refactor PaddingScheme into a trait#244
tarcieri merged 5 commits into
masterfrom
refactor-padding-scheme-into-trait

Conversation

@tarcieri

Copy link
Copy Markdown
Member

As proposed in #226, splits up the PaddingScheme enum into four structs, named after the previous variants of the struct (adopting capitalization from the Rust API guidelines):

  • oaep::Oaep
  • pkcs1v15::{Pkcs1v15Encrypt, Pkcs1v15Sign}
  • pss::Pss

All of these are re-exported from the toplevel.

Each of these structs impls one or more of the following traits:

  • PaddingScheme: used for encryption
  • SignatureScheme: used for signing

The PaddingScheme constructors have been remapped as follows:

  • new_oaep => Oaep::new
  • new_oaep_with_label => Oaep::new_with_label
  • new_oaep_with_mgf_hash => Oaep::new_with_mgf_hash
  • new_oaep_with_mgf_hash_with_label => Oaep::new_with_mgf_hash_and_label
  • new_pkcs1v15_encrypt => Pkcs1v15Encrypt
  • new_pkcs1v15_sign => Pkcs1v15Sign::new
  • new_pkcs1v15_sign_raw => Pkcs1v15Sign::new_raw
  • new_pss => Pss::{new, new_blinded}
  • new_pss_with_salt => Pss::{new_with_salt new_blinded_with_salt}

@tarcieri

Copy link
Copy Markdown
MemberAuthor

cc @lumag

@tarcieri

Copy link
Copy Markdown
MemberAuthor

Note that there's various additional refactoring that could probably be performed, like getting rid of the inherent methods for these functionality and using the traits exclusively, or getting rid of the SignatureScheme trait and factoring the relevant code into SigningKey and VerifyingKey.

I deliberately didn't make any of those kinds of changes to make code review easier.

@tarcieri
tarcieriforce-pushed the refactor-padding-scheme-into-trait branch from ef9650b to 610d257CompareJanuary 6, 2023 03:25
Comment threadsrc/key.rs Outdated
Comment threadsrc/oaep.rs Outdated
@dignifiedquire

Copy link
Copy Markdown
Member

I overall very much like this approach, it makes the API clearer to understand and reason about.

@tarcieri

Copy link
Copy Markdown
MemberAuthor

@dignifiedquire this should be good to go now

Comment threadsrc/key.rs Outdated
Comment threadsrc/key.rs Outdated
Splits up the `PaddingScheme` enum into four structs, named after the
previous variants of the struct (adopting capitalization from the Rust
API guidelines):
- `oaep::Oaep`
- `pkcs1v15::{Pkcs1v15Encrypt, Pkcs1v15Sign}`
- `pss::Pss`
All of these are re-exported from the toplevel.
Each of these structs impls one or more of the following traits:
- `PaddingScheme`: used for encryption
- `SignatureScheme`: used for signing
The `PaddingScheme` constructors have been remapped as follows:
- `new_oaep` => `Oaep::new`
- `new_oaep_with_label` => `Oaep::new_with_label`
- `new_oaep_with_mgf_hash` => `Oaep::new_with_mgf_hash`
- `new_oaep_with_mgf_hash_with_label` => `Oaep::new_with_mgf_hash_and_label`
- `new_pkcs1v15_encrypt` => `Pkcs1v15Encrypt`
- `new_pkcs1v15_sign` => `Pkcs1v15Sign::new`
- `new_pkcs1v15_sign_raw` => `Pkcs1v15Sign::new_raw`
- `new_pss` => `Pss::{new, new_blinded}`
- `new_pss_with_salt` => `Pss::{new_with_salt new_blinded_with_salt}`
@tarcieri
tarcieriforce-pushed the refactor-padding-scheme-into-trait branch from 69c9ba0 to dc47326CompareJanuary 10, 2023 16:45

@dignifiedquiredignifiedquire left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you, lgtm

@tarcieri
tarcieri merged commit 35372d9 into masterJan 10, 2023
@tarcieri
tarcieri deleted the refactor-padding-scheme-into-trait branch January 10, 2023 20:59
@tarcieritarcieri mentioned this pull request Jan 16, 2023
Merged
sorah added a commit to sorah/needroleshere that referenced this pull request Nov 4, 2023
Resolve incompatibilities as follows:
- src/certificate.rs: RustCrypto/formats#771
- src/cmd/serve.rs: Move to FromRequestParts and use headers crate
- src/ecdsa_sha256.rs: RustCrypto/traits#1196
and RustCrypto/signatures#574
- src/error.rs: Remove Duplicates
- src/identity.rs: Remove owned validation logic as it should be done at
x509_cert::serial_number::SerialNumber<x509_cert::certificate::Rfc5280>
- src/sign.rs: RustCrypto/RSA#244
takumi-earth pushed a commit to earthlings-dev/RSA that referenced this pull request Jan 27, 2026
Splits up the `PaddingScheme` enum into four structs, named after the
previous variants of the struct (adopting capitalization from the Rust
API guidelines):
- `oaep::Oaep`
- `pkcs1v15::{Pkcs1v15Encrypt, Pkcs1v15Sign}`
- `pss::Pss`
All of these are re-exported from the toplevel.
Each of these structs impls one or more of the following traits:
- `PaddingScheme`: used for encryption
- `SignatureScheme`: used for signing
The `PaddingScheme` constructors have been remapped as follows:
- `new_oaep` => `Oaep::new`
- `new_oaep_with_label` => `Oaep::new_with_label`
- `new_oaep_with_mgf_hash` => `Oaep::new_with_mgf_hash`
- `new_oaep_with_mgf_hash_with_label` => `Oaep::new_with_mgf_hash_and_label`
- `new_pkcs1v15_encrypt` => `Pkcs1v15Encrypt`
- `new_pkcs1v15_sign` => `Pkcs1v15Sign::new`
- `new_pkcs1v15_sign_raw` => `Pkcs1v15Sign::new_raw`
- `new_pss` => `Pss::{new, new_blinded}`
- `new_pss_with_salt` => `Pss::{new_with_salt new_blinded_with_salt}`
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@tarcieri@dignifiedquire