Skip to content

Commit 12d837a

Browse files
% == 0 changed into isMultiple (SE-0225 support)
1 parent 4c505c8 commit 12d837a

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

web3swift/KeystoreManager/Classes/BIP32Keystore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public class BIP32Keystore: AbstractKeystore {
238238
let derivedKeyLast16bytes = derivedKey[(derivedKey.count - 16)...(derivedKey.count - 1)]
239239
dataForMAC.append(derivedKeyLast16bytes)
240240
guard let cipherText = Data.fromHex(keystorePars.crypto.ciphertext) else {return nil}
241-
guard (cipherText.count % 32 == 0) else {return nil}
241+
guard (cipherText.count.isMultiple(of: 32)) else {return nil}
242242
dataForMAC.append(cipherText)
243243
let mac = dataForMAC.sha3(.keccak256)
244244
guard let calculatedMac = Data.fromHex(keystorePars.crypto.mac), mac.constantTimeComparisonTo(calculatedMac) else {return nil}

web3swift/KeystoreManager/Classes/BIP39.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ public class BIP39 {
9191
}
9292

9393
static public func generateMnemonics(bitsOfEntropy: Int, language: BIP39Language = BIP39Language.english) throws -> String? {
94-
guard bitsOfEntropy >= 128 && bitsOfEntropy <= 256 && bitsOfEntropy % 32 == 0 else {return nil}
94+
guard bitsOfEntropy >= 128 && bitsOfEntropy <= 256 && bitsOfEntropy.isMultiple(of: 32) else {return nil}
9595
guard let entropy = Data.randomBytes(length: bitsOfEntropy/8) else {throw AbstractKeystoreError.noEntropyError}
9696
return BIP39.generateMnemonicsFromEntropy(entropy: entropy, language: language)
9797

9898
}
9999

100100
static public func mnemonicsToEntropy(_ mnemonics: String, language: BIP39Language = BIP39Language.english) -> Data? {
101101
let wordList = mnemonics.components(separatedBy: " ")
102-
guard wordList.count >= 12 && wordList.count % 4 == 0 else {return nil}
102+
guard wordList.count >= 12 && wordList.count.isMultiple(of: 4) else {return nil}
103103
var bitString = ""
104104
for word in wordList {
105105
let idx = language.words.firstIndex(of: word)
@@ -111,7 +111,7 @@ public class BIP39 {
111111
bitString.append(stringForm)
112112
}
113113
let stringCount = bitString.count
114-
if stringCount % 33 != 0 {
114+
if !stringCount.isMultiple(of: 33) {
115115
return nil
116116
}
117117
let entropyBits = bitString[0 ..< (bitString.count - bitString.count/33)]

web3swift/Promises/Classes/Promise+Batching.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public class JSONRPCrequestDispatcher {
9999
throw Web3Error.inputError(desc: "Trying to batch a request when policy is not to batch")
100100
}
101101
let currentBatch = self.batches.last!
102-
if currentBatch.requests.count % batchLength == 0 || currentBatch.triggered {
102+
if currentBatch.requests.count.isMultiple(of: batchLength) || currentBatch.triggered {
103103
let newBatch = Batch(provider: self.provider, capacity: Int(batchLength), queue: self.queue, lockQueue: self.lockQueue)
104104
self.batches.append(newBatch)
105105
return newBatch

0 commit comments

Comments
 (0)