formats
formats copied to clipboard
pkcs8: provide `PrivateKeyInfoRef`/`PrivateKeyInfoOwned`
see #1117
Why are you exposing BytesRef
/BytesOwned
?
Why not OctetString
/OctetStringRef
ala spki
(i.e. the ASN.1 type, though it's BIT STRING there), or if not that then &'a [u8]
and Vec<u8>
?
Really BytesRef
and BytesOwned
exist for one reason: because they pre-check that the Length
is valid and thus permit operations which would otherwise be fallible. Otherwise they're just analogues for &'a [u8]
and Vec<u8>
.
I was actually looking for a &'a [u8]
/Box<[u8]>
tuple. But the BytesRef
/BytesOwned
was looking like the closest to that.
I don't think I'm too comfortable with OctetString
, went with just the &'a [u8]
/Box<[u8]>
and implement RefToOwned
there.
Why not OctetString/OctetStringRef
Why not merge OctetString
and OctetStringRef
into something like Cow<[u8]>
?
With minor CPU overhead an enum would be easier to maintain.
Regular OctetString would just contain Cow<'static, [u8]>
which is Vec<u8>
Ref OctetString would contain &'a [u8]
https://doc.rust-lang.org/std/vec/struct.Vec.html#impl-From%3CCow%3C'a,+%5BT%5D%3E%3E-for-Vec%3CT%3E
Also, conversions from/to owned would just swap an enum.
@dishmaker this crate is designed to support heapless targets that don’t have alloc
available, which OctetStringRef
is capable of working on
Ohhh so such Cow
feature needs a kill switch 😢
struct BytesRef<'a> {
pub length: Length,
#[cfg(feature = "alloc")]
pub inner: Cow<'a, [u8]>,
#[cfg(not(feature = "alloc"))]
pub inner: &'a [u8],
}
But then you haven't actually gotten rid of the *Ref
type, and since it's immutable anyway, there's no "write" case to worry about, so Cow
doesn't buy you anything.
Anyway, if you'd like to keep discussing this, it would probably be better to open a separate issue.
@baloo are you going to redo this? I think it would be great to get in before the next stable release series
I guess I could, I honestly lost track.
Aah ok, I'm down to take it then. Seems like it will be a bit of a mess but worth it.
The rebase looks like it's a mess indeed.
I can give it a shot, you have a fair amount of things on your hand.
Sure!