https://github.com/apple/swift-crypto/issues/338 pointed to some
availability guard platform mismatches on `ARC` and its extensions. This
PR aims to fix these and make sure all platforms build correctly.
### Motivation
The use of `Data.subdata(in:)` results in needless copies when decoding
fields from bytes. Additionally, the use of a long chain of
`Data.append(_:)` without a call to `Data.init(capacity:)` or
`Data.reserveCapacity(_:)` can result in needless reallocations.
### Modifications
- Remove unused `EncodeInt` and `DecodeInt` functions. They were unused
before this PR but are there from when ARC credential serialization
included the presentation limit. `DecodeInt` also happened to be
incorrect and would crash when called with a slice.
- Add some useful utility methods for popping bytes from a view without
copying.
- Add some generic functions for encoding and decoding
`FixedWidthInteger` types along with tests for concrete types over
`Data` and slices.
- In ARC decoding, replace the use of `Data.subdata(in:)` with code that
uses the `Data.Subsequence` slice (which happens to be `Data` since the
type is self-slicing).
- In ARC encoding, reserve enough capacity in the resulting `Data` when
the sizes are known to reduce allocations.
## Results
More performant serialization and deserialization for ARC types.
### Motivation
The latest draft of the ARC spec[0] includes moving where the
presentation limit is used. Before it was baked in when a client
constructed a credential request, but now it has moved to when a client
makes a presentation from a finalized credential. This PR updates the
internals and API surface to reflect this change.
### Modifications
- Defer passing the presentation limit until a presentation is made.
### Result
Align more closely with the published draft.
### API breakage
It's expected that this will result in the following _breaking_ API
changes:
```diff
- P384._ARCV1.PublicKey.prepareCredentialRequest(requestContext:presentationLimit:)
+ P384._ARCV1.PublicKey.prepareCredentialRequest(requestContext:)
```
```diff
- P384._ARCV1.Credential.makePresentation(context:)
+ P384._ARCV1.Credential.makePresentation(context:presentationLimit:)
```
As this is behind an underscored namespace, we deem this an acceptable
break.
[0]: https://datatracker.ietf.org/doc/draft-yun-cfrg-arc/
Minimum deployment versions in package manifests can be problematic for
libraries, because changing them or adding them to an existing package
that doesn't already use them forces SemVer breaking majors.
Furthermore, depending on a new library that specifies minimum
deployment targets would force the adopting library to also have to add
these platforms to its manifest (which would in turn force a major).
This PR removes the platforms stanza from the package manifest and
replaces them with availability guards.
This will allow more packages to use swift-crypto, without forcing them
to mint new majors to support the appropriate platforms.
---------
Co-authored-by: Cory Benfield <lukasa@apple.com>
Motivation
We should have proper availability annotations.
Modifications
Propagate the availability annotations we need.
Result
Compiles correctly on non-macOS platforms.
## Motivation
We would like to provide support for ARCV1(P-384), as defined in [IETF
Internet Draft: Anonymous Rate-Limited
Credentials](https://datatracker.ietf.org/doc/draft-yun-cfrg-arc/).
## Modifications
- Add internal implementation, generic over the NIST curves.
- Add public API for ARC(P-384), under `P384._ARCV1`.
## Result
New API for current draft of ARC.
## Tests
- End to end tests of internal implementation and API surface.
- Test vector tests of internal implementation and API surface, from the
spec draft.