Browse Source

Update Byte extension for bits. Bool -> Bit

Marcin Krzyżanowski 11 years ago
parent
commit
3c6fca1585
2 changed files with 7 additions and 7 deletions
  1. 5 5
      CryptoSwift/ByteExtension.swift
  2. 2 2
      CryptoSwift/IntExtension.swift

+ 5 - 5
CryptoSwift/ByteExtension.swift

@@ -11,17 +11,17 @@ import Foundation
 extension Byte {
 extension Byte {
     
     
     /** array of bits */
     /** array of bits */
-    internal func bits() -> [Bool] {
+    internal func bits() -> [Bit] {
         let totalBitsCount = sizeof(Byte) * 8
         let totalBitsCount = sizeof(Byte) * 8
         
         
-        var bitsArray:[Bool] = [Bool](count: totalBitsCount, repeatedValue: false)
+        var bitsArray:[Bit] = [Bit](count: totalBitsCount, repeatedValue: Bit.zero)
         
         
         for j in 0..<totalBitsCount {
         for j in 0..<totalBitsCount {
             let bitVal:Byte = 1 << UInt8(totalBitsCount - 1 - j)
             let bitVal:Byte = 1 << UInt8(totalBitsCount - 1 - j)
             let check = self & bitVal
             let check = self & bitVal
             
             
             if (check != 0) {
             if (check != 0) {
-                bitsArray[j] = true;
+                bitsArray[j] = Bit.one;
             }
             }
         }
         }
         return bitsArray
         return bitsArray
@@ -29,9 +29,9 @@ extension Byte {
     
     
     internal func bits() -> String {
     internal func bits() -> String {
         var s = String()
         var s = String()
-        let arr:[Bool] = self.bits()
+        let arr:[Bit] = self.bits()
         for (idx,b) in enumerate(arr) {
         for (idx,b) in enumerate(arr) {
-            s += (b ? "1" : "0")
+            s += (b == Bit.one ? "1" : "0")
             if ((idx + 1) % 8 == 0) { s += " " }
             if ((idx + 1) % 8 == 0) { s += " " }
         }
         }
         return s
         return s

+ 2 - 2
CryptoSwift/IntExtension.swift

@@ -60,10 +60,10 @@ extension UInt64 {
 
 
 extension Int {
 extension Int {
     
     
-    private init(bits: [Bool]) {
+    private init(bits: [Bit]) {
         var bitPattern:UInt = 0
         var bitPattern:UInt = 0
         for (idx,b) in enumerate(bits) {
         for (idx,b) in enumerate(bits) {
-            if (b == true) {
+            if (b == Bit.one) {
                 var bit:UInt = UInt(1) << UInt(idx)
                 var bit:UInt = UInt(1) << UInt(idx)
                 bitPattern = bitPattern | bit
                 bitPattern = bitPattern | bit
             }
             }