diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..a8465c1 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,22 @@ +name: Build and Test +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + test: + runs-on: ubuntu-latest + container: swift:noble + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Lint + run: swift-format lint --recursive --strict --parallel . + - name: Build + run: swift build + - name: Test + run: swift test + + \ No newline at end of file diff --git a/Sources/Bcrypt/Base64.swift b/Sources/Bcrypt/Base64.swift index abc697c..059899d 100644 --- a/Sources/Bcrypt/Base64.swift +++ b/Sources/Bcrypt/Base64.swift @@ -38,10 +38,7 @@ struct Base64 { return [] } - var len = count - if len > bytes.count { - len = bytes.count - } + let len = min(bytes.count, count) var offset: Int = 0 var c1: UInt8 @@ -51,7 +48,7 @@ struct Base64 { while offset < len { c1 = bytes[offset] & 0xff offset &+= 1 - result.append(encodingTable[Int(truncatingIfNeeded: (c1 >> 2) & 0x3f)]) + result.append(encodingTable[Int(truncatingIfNeeded: (c1 &>> 2) & 0x3f)]) c1 = (c1 & 0x03) &<< 4 if offset >= len { result.append(encodingTable[Int(truncatingIfNeeded: c1 & 0x3f)]) @@ -79,7 +76,7 @@ struct Base64 { } private static func char64(of x: UInt8) -> UInt8 { - x > 127 ? 255 : decodingTable[Int(x)] + x > 127 ? 255 : decodingTable[Int(truncatingIfNeeded: x)] } @usableFromInline