Skip to content

Commit 9588771

Browse files
committed
chore: notes for future option
1 parent 15ee17f commit 9588771

3 files changed

Lines changed: 23 additions & 21 deletions

File tree

ios/FileHash.swift

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -131,28 +131,28 @@ public class FileHashImpl: NSObject {
131131
private func decodeKey(_ key: String, encoding: String?) -> Data? {
132132
let enc = (encoding ?? "utf8").lowercased()
133133
switch enc {
134-
case "utf8":
135-
return key.data(using: .utf8)
136-
case "hex":
137-
let cleaned = key.replacingOccurrences(of: " ", with: "")
138-
guard cleaned.count % 2 == 0 else { return nil }
139-
var data = Data(capacity: cleaned.count / 2)
140-
var idx = cleaned.startIndex
141-
while idx < cleaned.endIndex {
142-
let nextIdx = cleaned.index(idx, offsetBy: 2)
143-
let byteString = cleaned[idx..<nextIdx]
144-
if let num = UInt8(byteString, radix: 16) {
145-
data.append(num)
146-
} else {
147-
return nil
134+
case "utf8":
135+
return key.data(using: .utf8)
136+
case "hex":
137+
let cleaned = key.replacingOccurrences(of: " ", with: "")
138+
guard cleaned.count % 2 == 0 else { return nil }
139+
var data = Data(capacity: cleaned.count / 2)
140+
var idx = cleaned.startIndex
141+
while idx < cleaned.endIndex {
142+
let nextIdx = cleaned.index(idx, offsetBy: 2)
143+
let byteString = cleaned[idx..<nextIdx]
144+
if let num = UInt8(byteString, radix: 16) {
145+
data.append(num)
146+
} else {
147+
return nil
148+
}
149+
idx = nextIdx
148150
}
149-
idx = nextIdx
150-
}
151-
return data
152-
case "base64":
153-
return Data(base64Encoded: key)
154-
default:
155-
return nil
151+
return data
152+
case "base64":
153+
return Data(base64Encoded: key)
154+
default:
155+
return nil
156156
}
157157
}
158158

src/NativeFileHash.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type HashOptions = {
1717
mode?: THashMode;
1818
key?: string;
1919
keyEncoding?: TKeyEncoding;
20+
// outputEncoding?: 'hex' | 'base64'; // TODO: Future option for output encoding
2021
};
2122
export interface Spec extends TurboModule {
2223
fileHash(

src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type HmacCapable = Extract<
1212
'SHA-224' | 'SHA-256' | 'SHA-384' | 'SHA-512'
1313
>;
1414

15+
// TODO: replace this check into native-side validation
1516
const decodeKey = (
1617
key: string,
1718
encoding: TKeyEncoding = 'utf8'

0 commit comments

Comments
 (0)