mirror of
				https://github.com/GayPizzaSpecifications/darwin-apk.git
				synced 2025-11-03 23:49:38 +00:00 
			
		
		
		
	Generalise digest hex conversion
This commit is contained in:
		@ -105,28 +105,7 @@ extension ApkIndexDigest.DigestType: CustomStringConvertible {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extension ApkIndexDigest: CustomStringConvertible {
 | 
					extension ApkIndexDigest: CustomStringConvertible {
 | 
				
			||||||
#if DEBUG
 | 
					 | 
				
			||||||
  private static let hex = Array("0123456789ABCDEF".unicodeScalars)
 | 
					 | 
				
			||||||
  public var description: String {
 | 
					  public var description: String {
 | 
				
			||||||
    var s = "[\(self.type)] "
 | 
					    return "[\(self.type)] \(self.data.asHexString)"
 | 
				
			||||||
    s.reserveCapacity(10 + self.data.count * 2)
 | 
					 | 
				
			||||||
    Self.hex.withUnsafeBufferPointer { hp in
 | 
					 | 
				
			||||||
      for b in self.data {
 | 
					 | 
				
			||||||
        s.unicodeScalars.append(hp[Int(b >> 4)])
 | 
					 | 
				
			||||||
        s.unicodeScalars.append(hp[Int(b & 15)])
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    return s
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
  private static let hex = "0123456789ABCDEF".map(\.asciiValue!)
 | 
					 | 
				
			||||||
  public var description: String {
 | 
					 | 
				
			||||||
    Self.hex.withUnsafeBufferPointer { hp in
 | 
					 | 
				
			||||||
      let hexChars = self.data.flatMap { b in
 | 
					 | 
				
			||||||
        [hp[Int(b >> 4)], hp[Int(b & 15)]]
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      return "[\(self.type)] \(String(bytes: hexChars, encoding: .ascii)!)"
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -29,4 +29,29 @@ extension Data {
 | 
				
			|||||||
      self.append(byte)
 | 
					      self.append(byte)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if DEBUG
 | 
				
			||||||
 | 
					  private static let hex = Array("0123456789ABCDEF".unicodeScalars)
 | 
				
			||||||
 | 
					  var asHexString: String {
 | 
				
			||||||
 | 
					    var s = ""
 | 
				
			||||||
 | 
					    s.reserveCapacity(self.count * 2)
 | 
				
			||||||
 | 
					    Self.hex.withUnsafeBufferPointer { hp in
 | 
				
			||||||
 | 
					      for b in self {
 | 
				
			||||||
 | 
					        s.unicodeScalars.append(hp[Int(b >> 4)])
 | 
				
			||||||
 | 
					        s.unicodeScalars.append(hp[Int(b & 15)])
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return s
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					  private static let hex = "0123456789ABCDEF".map(\.asciiValue!)
 | 
				
			||||||
 | 
					  var asHexString: String {
 | 
				
			||||||
 | 
					    Self.hex.withUnsafeBufferPointer { hp in
 | 
				
			||||||
 | 
					      let hexChars = self.flatMap { b in
 | 
				
			||||||
 | 
					        [hp[Int(b >> 4)], hp[Int(b & 15)]]
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      return String(bytes: hexChars, encoding: .ascii)!
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user