Skip to content

Commit 2150c00

Browse files
author
Alex Vlasov
committed
fix keystore error when regenerating with invalid old password
1 parent 9165f45 commit 2150c00

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

web3swift/KeystoreManager/Classes/BIP32Keystore.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ public class BIP32Keystore: AbstractKeystore {
183183

184184
public func regenerate(oldPassword: String, newPassword: String, dkLen: Int=32, N: Int = 262144, R: Int = 8, P: Int = 1) throws {
185185
var keyData = try self.getPrefixNodeData(oldPassword)
186+
if keyData == nil {
187+
throw AbstractKeystoreError.encryptionError("Failed to decrypt a keystore")
188+
}
186189
defer {Data.zero(&keyData!)}
187190
try self.encryptDataToStorage(newPassword, data: keyData!)
188191
}

web3swift/KeystoreManager/Classes/EthereumKeystoreV3.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ public class EthereumKeystoreV3: AbstractKeystore {
106106

107107
public func regenerate(oldPassword: String, newPassword: String, dkLen: Int=32, N: Int = 262144, R: Int = 8, P: Int = 1) throws {
108108
var keyData = try self.getKeyData(oldPassword)
109+
if keyData == nil {
110+
throw AbstractKeystoreError.encryptionError("Failed to decrypt a keystore")
111+
}
109112
defer {Data.zero(&keyData!)}
110113
try self.encryptDataToStorage(newPassword, keyData: keyData!)
111114
}

0 commit comments

Comments
 (0)