Browse Source

Never underestimate random memory value

Marcin Krzyżanowski 11 years ago
parent
commit
f932cfbbc9
2 changed files with 2 additions and 13 deletions
  1. 1 1
      CryptoSwift/StringExtension.swift
  2. 1 12
      CryptoSwiftTests/HashTests.swift

+ 1 - 1
CryptoSwift/StringExtension.swift

@@ -13,7 +13,7 @@ extension String {
     
     /** Calculate MD5 hash */
     public func md5() -> String? {
-        var stringData = self.dataUsingEncoding(NSASCIIStringEncoding, allowLossyConversion: false)
+        var stringData = self.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
         if var data = stringData!.md5() {
             return data.hexString
         }

+ 1 - 12
CryptoSwiftTests/HashTests.swift

@@ -21,7 +21,6 @@ class CryptoSwiftTests: XCTestCase {
     
     func testMD5() {
         let data1:NSData = NSData(bytes: [0x31, 0x32, 0x33] as [Byte], length: 3) // "1", "2", "3"
-        let data2:NSData = NSData(bytes: [0x31, 0x32, 0x33] as [Byte], length: 3) // "1", "2", "3"
         
         if let d = MD5(data1).calculate() {
             XCTAssertEqual(d.hexString, "202CB962AC59075B964B07152D234B70", "MD5 calculation failed");
@@ -29,17 +28,7 @@ class CryptoSwiftTests: XCTestCase {
             XCTFail("MD5 fail")
         }
         
-        //FIXME: fail on 32-bit simulator for some unknown reason.
-        //       because it's working fine for the first time, and break for the second
-        //       time with the very same input data
-        if let d = MD5(data2).calculate() {
-            XCTAssertEqual(d.hexString, "202CB962AC59075B964B07152D234B70", "MD5 calculation failed");
-        } else {
-            XCTFail("MD5 fail")
-        }
-
-        let string = "123"
-        if let hash = string.md5() {
+        if let hash = "123".md5() {
             XCTAssertEqual(hash, "202CB962AC59075B964B07152D234B70", "MD5 calculation failed");
         } else {
             XCTFail("MD5 fail")