Skip to content

Commit 80fcc7f

Browse files
japwiktor-k
andcommitted
Add an option to Cert.generate to explicitly select v4/v6 keys
Co-authored-by: Wiktor Kwapisiewicz <wiktor@metacode.biz> Signed-off-by: Jasper Spaans <jasper@startmail.com>
1 parent f33d1ce commit 80fcc7f

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package is for you!
1515
[OpenPGP]: https://en.wikipedia.org/wiki/Pretty_Good_Privacy#OpenPGP
1616
[SQ]: https://sequoia-pgp.org/
1717
[4880]: https://www.rfc-editor.org/rfc/rfc4880
18+
[9580]: https://www.rfc-editor.org/rfc/rfc9580
1819

1920
Note: This is a work in progress. The API is **not** stable!
2021

@@ -295,6 +296,20 @@ encrypted = encrypt(signer = alice.secrets.signer(), recipients = [bob], bytes =
295296
print(f"Encrypted data: {encrypted}")
296297
```
297298

299+
The default is to generate keys according to [RFC4880][4880]. By
300+
providing a `profile` parameter to the generate function, [modern PGP
301+
keys][9580] can also be generated:
302+
303+
```python
304+
from pysequoia import Profile
305+
306+
mary = Cert.generate("Modern Mary <mary@example.com", profile=Profile.RFC9580)
307+
print(f"Generated cert with fingerprint {mary.fingerprint}:\n{mary}")
308+
```
309+
310+
Note that legacy PGP implementations may not be able to consume these
311+
certificates yet.
312+
298313
### merge
299314

300315
Merges packets from a new version into an old version of a certificate:

src/cert.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ impl Cert {
4646
}
4747
}
4848

49+
#[derive(Clone, Copy, Default)]
50+
#[pyclass]
51+
pub enum Profile {
52+
#[default]
53+
RFC4880,
54+
RFC9580,
55+
}
56+
57+
impl From<Profile> for sequoia_openpgp::Profile {
58+
fn from(profile: Profile) -> Self {
59+
match profile {
60+
Profile::RFC4880 => sequoia_openpgp::Profile::RFC4880,
61+
Profile::RFC9580 => sequoia_openpgp::Profile::RFC9580,
62+
}
63+
}
64+
}
65+
4966
pub mod secret;
5067

5168
#[pymethods]
@@ -81,9 +98,14 @@ impl Cert {
8198
}
8299

83100
#[staticmethod]
84-
#[pyo3(signature = (user_id=None, user_ids=None))]
85-
pub fn generate(user_id: Option<&str>, user_ids: Option<Vec<String>>) -> PyResult<Self> {
101+
#[pyo3(signature = (user_id=None, user_ids=None, profile=None))]
102+
pub fn generate(
103+
user_id: Option<&str>,
104+
user_ids: Option<Vec<String>>,
105+
profile: Option<Profile>,
106+
) -> PyResult<Self> {
86107
let mut builder = CertBuilder::new()
108+
.set_profile(profile.unwrap_or_default().into())?
87109
.set_cipher_suite(CipherSuite::default())
88110
.set_primary_key_flags(KeyFlags::empty().set_certification())
89111
.set_validity_period(std::time::Duration::new(3 * 52 * 7 * 24 * 60 * 60, 0))

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ impl Decrypted {
9393
#[pymodule]
9494
fn pysequoia(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
9595
m.add_class::<cert::Cert>()?;
96+
m.add_class::<cert::Profile>()?;
9697
m.add_class::<signature::Sig>()?;
9798
m.add_class::<notation::Notation>()?;
9899
m.add_class::<sign::SignatureMode>()?;

0 commit comments

Comments
 (0)