Skip to content

Commit 36fb3fe

Browse files
committed
Mark functions, structs, and other objects as internal
This should finally allow all platforms to build the package without errors.
1 parent 60cd872 commit 36fb3fe

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

Sources/ATCryptography/Extensions/P256Extensions.swift

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,15 @@ import BigInt
1111

1212
extension P256.Signing.PublicKey {
1313

14-
/// Returns the compressed SEC1 representation of a P256 public key,
14+
/// Returns the compressed SEC1 representation of a p256 public key,
1515
/// compatible with platforms where `.compressedRepresentation` is unavailable.
1616
///
1717
/// The compressed form includes only the X coordinate and a prefix byte
1818
/// (0x02 for even Y, 0x03 for odd Y), following the SEC1 standard.
1919
///
2020
/// - Returns: A 33-byte compressed public key.
2121
/// - Throws: An error if the raw representation is invalid or not uncompressed.
22-
@available(iOS, introduced: 13, obsoleted: 16)
23-
@available(tvOS, introduced: 13, obsoleted: 16)
24-
public func compressedRepresentationCompat() throws -> Data {
22+
internal func compressedRepresentationCompat() throws -> Data {
2523
let rawKey = self.rawRepresentation
2624

2725
// Ensure it’s exactly 64 bytes: 32 bytes for X, 32 for Y.
@@ -40,7 +38,7 @@ extension P256.Signing.PublicKey {
4038
return Data([prefixByte]) + xCoordinate
4139
}
4240

43-
/// Decompresses a compressed P256 public key into a full uncompressed SEC1 key,
41+
/// Decompresses a compressed p256 public key into a full uncompressed SEC1 key,
4442
/// and initializes a `P256.Signing.PublicKey` from it.
4543
///
4644
/// This function is designed to support older Apple platforms (iOS/tvOS 13–15)
@@ -49,10 +47,10 @@ extension P256.Signing.PublicKey {
4947
/// - Parameter compressedKey: The SEC1 compressed public key data.
5048
/// - Returns: A valid `P256.Signing.PublicKey`.
5149
/// - Throws: `P256Error.invalidCompressedKey` or `P256Error.pointNotOnCurve`
52-
/// if the data is malformed or does not represent a point on the P256 curve.
50+
/// if the data is malformed or does not represent a point on the p256 curve.
5351
@available(iOS, introduced: 13, obsoleted: 16)
5452
@available(tvOS, introduced: 13, obsoleted: 16)
55-
public static func decompressP256PublicKey(compressed compressedKey: Data) throws -> P256.Signing.PublicKey {
53+
internal static func decompressP256PublicKey(compressed compressedKey: Data) throws -> P256.Signing.PublicKey {
5654
guard compressedKey.count == 33 else {
5755
throw P256Error.invalidCompressedKey
5856
}
@@ -131,59 +129,64 @@ extension Data {
131129

132130
/// Pads the current `Data` instance with leading zeroes to match the specified length.
133131
///
134-
/// This is commonly used to ensure big-endian encoded integers or coordinates are a fixed size,
135-
/// such as 32 bytes for P256 public key components.
132+
/// This is commonly used to ensure big-endian encoded integers or coordinates are a fixed size, such as
133+
/// 32 bytes for p256 public key components.
136134
///
137135
/// - Parameter length: The target length in bytes.
138136
/// - Returns: A new `Data` instance of exactly `length` bytes, with leading zeroes added if necessary.
139137
/// If the current length is already `>= length`, the original data is returned unchanged.
140138
@available(iOS, introduced: 13, obsoleted: 16)
141139
@available(tvOS, introduced: 13, obsoleted: 16)
142-
public func pad(to length: Int) -> Data {
140+
internal func pad(to length: Int) -> Data {
143141
if count >= length { return self }
144142
return Data(repeating: 0, count: length - count) + self
145143
}
146144
}
147145

148-
/// Utility for compressing and decompressing P256 public keys on platforms
149-
/// where native CryptoKit support for compressed keys is unavailable.
146+
/// Utility for compressing and decompressing p256 public keys on platforms where native CryptoKit support
147+
/// for compressed keys is unavailable.
150148
///
151-
/// This wrapper supports SEC1 compressed key encoding (33 bytes) and
152-
/// decoding by reconstructing the full point on the curve using the
153-
/// Weierstrass equation.
149+
/// This wrapper supports SEC1 compressed key encoding (33 bytes) and decoding by reconstructing the full
150+
/// point on the curve using the Weierstrass equation.
154151
///
155-
/// Use this only on iOS/tvOS 13–15. Prefer native CryptoKit APIs
156-
/// on newer platforms.
157-
@available(iOS, introduced: 13, obsoleted: 16)
158-
@available(tvOS, introduced: 13, obsoleted: 16)
159-
public struct CompressedP256 {
160-
161-
/// Compresses a P256 public key using SEC1 encoding.
152+
/// Use this only on iOS and tvOS 13–15. Prefer native CryptoKit APIs on newer platforms.
153+
@available(iOS, deprecated: 16, renamed: "P256.Signing.PublicKey.init(compressedRepresentation:)", message: "Use the initializer 'P256.Signing.PublicKey(compressedRepresentation:)' available on iOS 16 and later.")
154+
@available(tvOS, deprecated: 16, renamed: "P256.Signing.PublicKey.init(compressedRepresentation:)", message: "Use the initializer 'P256.Signing.PublicKey(compressedRepresentation:)' available on tvOS 16 and later.")
155+
@available(macOS, renamed: "P256.Signing.PublicKey.init(compressedRepresentation:)", message: "Use the initializer 'P256.Signing.PublicKey(compressedRepresentation:)' available on macOS.")
156+
@available(visionOS, renamed: "P256.Signing.PublicKey.init(compressedRepresentation:)", message: "Use the initializer 'P256.Signing.PublicKey(compressedRepresentation:)' available on visionOS.")
157+
@available(watchOS, renamed: "P256.Signing.PublicKey.init(compressedRepresentation:)", message: "Use the initializer 'P256.Signing.PublicKey(compressedRepresentation:)' available on watchOS.")
158+
internal struct CompressedP256 {
159+
160+
/// Compresses a p256 public key using SEC1 encoding.
162161
///
163-
/// - Parameter key: A valid uncompressed P256 public key.
162+
/// - Parameter key: A valid uncompressed p256 public key.
164163
/// - Returns: A 33-byte compressed SEC1 representation.
165164
///
166165
/// - Throws: If compression fails (e.g., invalid raw data).
167-
public static func compress(_ key: P256.Signing.PublicKey) throws -> Data {
166+
internal static func compress(_ key: P256.Signing.PublicKey) throws -> Data {
168167
return try key.compressedRepresentationCompat()
169168
}
170169

171-
/// Decompresses a SEC1 compressed public key into a usable P256 public key.
170+
/// Decompresses a SEC1 compressed public key into a usable p256 public key.
172171
///
173172
/// - Parameter data: A 33-byte compressed key.
174173
/// - Returns: A full `P256.Signing.PublicKey`.
174+
///
175175
/// - Throws: `P256Error` if the key is malformed or cannot be decompressed.
176-
public static func decompress(_ data: Data) throws -> P256.Signing.PublicKey {
176+
internal static func decompress(_ data: Data) throws -> P256.Signing.PublicKey {
177177
return try P256.Signing.PublicKey.decompressP256PublicKey(compressed: data)
178178
}
179179
}
180180

181-
/// Errors that may occur while working with compressed P256 keys.
182-
@available(iOS, introduced: 13, obsoleted: 16)
183-
@available(tvOS, introduced: 13, obsoleted: 16)
184-
public enum P256Error: Error {
181+
/// Errors that may occur while working with compressed p256 keys.
182+
@available(iOS, deprecated: 16, message: "")
183+
@available(tvOS, deprecated: 16, message: "")
184+
@available(macOS, message: "")
185+
@available(visionOS, message: "")
186+
@available(watchOS, message: "")
187+
internal enum P256Error: Error {
185188

186-
/// The input data is not a valid compressed P256 key.
189+
/// The input data is not a valid compressed p256 key.
187190
case invalidCompressedKey
188191

189192
/// The calculated Y coordinate is not a valid point on the curve.

0 commit comments

Comments
 (0)