Skip to content

Commit

Permalink
Update truncate parameter name
Browse files Browse the repository at this point in the history
  • Loading branch information
waahm7 committed Feb 8, 2024
1 parent aa5ffd6 commit 428cfc9
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions Source/AwsCommonRuntimeKit/crt/Hash.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ public class Hash {
}
}

public func finalize(truncate: Int = 0) throws -> Data {
public func finalize(truncateTo: Int = 0) throws -> Data {
var bufferData = Data(count: algorithm.size)
try bufferData.withUnsafeMutableBytes { bufferPointer in
var buffer = aws_byte_buf_from_empty_array(bufferPointer.baseAddress, algorithm.size)
guard aws_hash_finalize(rawValue, &buffer, truncate) == AWS_OP_SUCCESS else {
guard aws_hash_finalize(rawValue, &buffer, truncateTo) == AWS_OP_SUCCESS else {
throw CommonRunTimeError.crtError(.makeFromLastError())
}
}
Expand All @@ -67,16 +67,15 @@ extension Data {

/// Computes the md5 hash over data. Use this if you don't need to stream the data you're hashing and you can load
/// the entire input to hash into memory.
/// - Parameter truncate: If you specify truncate something other than 0, the output will be truncated to that number of bytes.
public func computeMD5(truncate: Int = 0) throws -> Data {
/// - Parameter truncateTo: If you specify truncate something other than 0, the output will be truncated to that number of bytes.
public func computeMD5(truncateTo: Int = 0) throws -> Data {
try self.withUnsafeBytes { bufferPointer in
var byteCursor = aws_byte_cursor_from_array(bufferPointer.baseAddress, count)

let bufferSize = 16
var bufferData = Data(count: bufferSize)
try bufferData.withUnsafeMutableBytes { bufferPointer in
var buffer = aws_byte_buf_from_empty_array(bufferPointer.baseAddress, bufferSize)
guard aws_md5_compute(allocator.rawValue, &byteCursor, &buffer, truncate) == AWS_OP_SUCCESS else {
guard aws_md5_compute(allocator.rawValue, &byteCursor, &buffer, truncateTo) == AWS_OP_SUCCESS else {
throw CommonRunTimeError.crtError(.makeFromLastError())
}
}
Expand All @@ -85,16 +84,16 @@ extension Data {
}

/// Computes the sha256 hash over data.
/// - Parameter truncate: If you specify truncate something other than 0, the output will be truncated to that number of bytes. For
/// - Parameter truncateTo: If you specify truncate something other than 0, the output will be truncated to that number of bytes. For
/// example, if you want a SHA256 digest as the first 16 bytes, set truncate to 16.
public func computeSHA256(truncate: Int = 0) throws -> Data {
public func computeSHA256(truncateTo: Int = 0) throws -> Data {
try self.withUnsafeBytes { bufferPointer in
var byteCursor = aws_byte_cursor_from_array(bufferPointer.baseAddress, count)
let bufferSize = Int(AWS_SHA256_LEN)
var bufferData = Data(count: bufferSize)
try bufferData.withUnsafeMutableBytes { bufferDataPointer in
var buffer = aws_byte_buf_from_empty_array(bufferDataPointer.baseAddress, bufferSize)
guard aws_sha256_compute(allocator.rawValue, &byteCursor, &buffer, truncate) == AWS_OP_SUCCESS else {
guard aws_sha256_compute(allocator.rawValue, &byteCursor, &buffer, truncateTo) == AWS_OP_SUCCESS else {
throw CommonRunTimeError.crtError(.makeFromLastError())
}
}
Expand All @@ -103,16 +102,16 @@ extension Data {
}

/// Computes the sha1 hash over data.
/// - Parameter truncate: If you specify truncate something other than 0, the output will be truncated to that number of bytes. For
/// - Parameter truncateTo: If you specify truncate something other than 0, the output will be truncated to that number of bytes. For
/// example, if you want a SHA1 digest as the first 10 bytes, set truncate to 10.
public func computeSHA1(truncate: Int = 0) throws -> Data {
public func computeSHA1(truncateTo: Int = 0) throws -> Data {
try self.withUnsafeBytes { bufferPointer in
var byteCursor = aws_byte_cursor_from_array(bufferPointer.baseAddress, count)
let bufferSize = Int(AWS_SHA1_LEN)
var bufferData = Data(count: bufferSize)
try bufferData.withUnsafeMutableBytes { bufferDataPointer in
var buffer = aws_byte_buf_from_empty_array(bufferDataPointer.baseAddress, bufferSize)
guard aws_sha1_compute(allocator.rawValue, &byteCursor, &buffer, truncate) == AWS_OP_SUCCESS else {
guard aws_sha1_compute(allocator.rawValue, &byteCursor, &buffer, truncateTo) == AWS_OP_SUCCESS else {
throw CommonRunTimeError.crtError(.makeFromLastError())
}
}
Expand Down

0 comments on commit 428cfc9

Please sign in to comment.