Brandon Toms 3 жил өмнө
parent
commit
a2cbfa193a

+ 10 - 1
Sources/CryptoSwift/ASN1/ASN1Encoder.swift

@@ -22,6 +22,9 @@ extension ASN1 {
     ///
     /// - Parameter node: The Node to encode
     /// - Returns: The encoded bytes as a UInt8 array
+    ///
+    /// - Warning: This ASN.1 encoder has only been tested to work on certain ASN.1 data structures such as DER and PEM files. Before using this encoder for another application, ensure you test it's behavior accordingly.
+    /// - Warning: This encoder makes no assumptions regarding Integer bit layout and signage. The proper serialization of your Integers is left up to the user.
     public static func encode(_ node: ASN1.Node) -> [UInt8] {
       switch node {
         case .integer(let integer):
@@ -42,6 +45,9 @@ extension ASN1 {
     }
 
     /// Calculates and returns the ASN.1 length Prefix for a chunk of data
+    ///
+    /// - Parameter bytes: The bytes to be length prefixed
+    /// - Returns: The ASN.1 length Prefix for this chuck of data (excluding the passed in data)
     private static func asn1LengthPrefix(_ bytes: [UInt8]) -> [UInt8] {
       if bytes.count >= 0x80 {
         var lengthAsBytes = withUnsafeBytes(of: bytes.count.bigEndian, Array<UInt8>.init)
@@ -52,7 +58,10 @@ extension ASN1 {
       }
     }
 
-    /// Returns the provided bytes with the appropriate ASN.1 length prefix prepended
+    /// Prefixes the provided bytes with the appropriate ASN.1 length prefix
+    ///
+    /// - Parameter bytes: The bytes to be length prefixed
+    /// - Returns: The provided bytes with the appropriate ASN.1 length prefix prepended
     private static func asn1LengthPrefixed(_ bytes: [UInt8]) -> [UInt8] {
       self.asn1LengthPrefix(bytes) + bytes
     }