-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Securityin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Milestone
Description
Background and motivation
Today, PemEncoding works on inputs of char, either arrays or spans, which implies UTF-16 encoded data. There has been the occasional need to work with UTF-8 encoded PEM structures, and will be needed in #91763.
This proposal is to extend PemEncoding to work with UTF-8 inputs and outputs.
Out of scope: new overloads of the many PEM APIs that have already been added throughout various cryptographic primitives will not gain UTF-8 overloads. Just the PemEncoding class.
API Proposal
namespace System.Security.Cryptography;
public static partial class PemEncoding {
+ public static PemFields FindUtf8(ReadOnlySpan<byte> pemData);
+ public static bool TryFindUtf8(ReadOnlySpan<byte> pemData, out PemFields fields);
+ public static bool TryWriteUtf8(ReadOnlySpan<byte> label, ReadOnlySpan<byte> data, Span<byte> destination, out int bytesWritten);
+ public static byte[] WriteUtf8(ReadOnlySpan<byte> label, System.ReadOnlySpan<byte> data);
}Some remarks.
PemFieldsis entirely based onRange, which worked out well in this case so we don't need a new return type.labelis aReadOnlySpan<byte>. It is expected that literals are almost always going to be used here though, like"CERTIFICATE"u8. We could continue to accept acharhere instead, but would force use to do a UTF-16 to UTF-8 conversion. Since the compiler can do the conversion for us in the case of literals, it made sense to accept a UTF-8 ROS<byte>.
API Usage
Same as the existing UTF-16 inputs, except for UTF-8.
Alternative Designs
No response
Risks
No response
PaulusParssinen and neon-sunset
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Securityin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged