Skip to content

Commit cb0acc3

Browse files
committed
More PR changes
1 parent 1e9b565 commit cb0acc3

File tree

5 files changed

+267
-91
lines changed

5 files changed

+267
-91
lines changed

NOTICES.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,28 @@ It also uses derivations of SwiftNIO's lock 'NIOLock.swift' and locked value box
3131

3232
---
3333

34+
This product uses derivations of SwiftNIO's HTTP2 implementation 'HPACKHeader.swift'.
35+
36+
* LICENSE (Apache License 2.0):
37+
* https://github.com/apple/swift-nio-http2/blob/main/LICENSE.txt
38+
* HOMEPAGE:
39+
* https://github.com/apple/swift-nio-http2
40+
41+
---
42+
3443
This product contains a derivation of the backpressure aware async stream from
3544
the Swift project.
3645

3746
* LICENSE (Apache License 2.0):
3847
* https://github.com/apple/swift/blob/main/LICENSE.txt
3948
* HOMEPAGE:
4049
* https://github.com/apple/swift
50+
51+
---
52+
53+
This product uses derivations of swift-extras/swift-extras-base64 'Base64.swift'.
54+
55+
* LICENSE (Apache License 2.0):
56+
* https://github.com/swift-extras/swift-extras-base64/blob/main/LICENSE
57+
* HOMEPAGE:
58+
* https://github.com/swift-extras/swift-extras-base64

Sources/GRPCCore/Internal/Base64.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,25 @@
7070
SOFTWARE.
7171
*/
7272

73-
public enum Base64 {}
73+
internal enum Base64 {}
7474

7575
extension Base64 {
76-
public struct DecodingOptions: OptionSet {
77-
public let rawValue: UInt
78-
public init(rawValue: UInt) { self.rawValue = rawValue }
76+
internal struct DecodingOptions: OptionSet {
77+
internal let rawValue: UInt
78+
internal init(rawValue: UInt) { self.rawValue = rawValue }
7979

80-
public static let base64UrlAlphabet = DecodingOptions(rawValue: UInt(1 << 0))
81-
public static let omitPaddingCharacter = DecodingOptions(rawValue: UInt(1 << 1))
80+
internal static let base64UrlAlphabet = DecodingOptions(rawValue: UInt(1 << 0))
81+
internal static let omitPaddingCharacter = DecodingOptions(rawValue: UInt(1 << 1))
8282
}
8383

84-
public enum DecodingError: Error, Equatable {
84+
internal enum DecodingError: Error, Equatable {
8585
case invalidLength
8686
case invalidCharacter(UInt8)
8787
case unexpectedPaddingCharacter
8888
case unexpectedEnd
8989
}
9090

91-
public static func decode(string encoded: String, options: DecodingOptions = []) throws -> [UInt8]
91+
internal static func decode(string encoded: String, options: DecodingOptions = []) throws -> [UInt8]
9292
{
9393
let decoded = try encoded.utf8.withContiguousStorageIfAvailable {
9494
(characterPointer) -> [UInt8] in
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright 2023, gRPC Authors All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
//===----------------------------------------------------------------------===//
17+
//
18+
// This source file is part of the SwiftNIO open source project
19+
//
20+
// Copyright (c) 2017-2023 Apple Inc. and the SwiftNIO project authors
21+
// Licensed under Apache License v2.0
22+
//
23+
// See LICENSE.txt for license information
24+
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
25+
//
26+
// SPDX-License-Identifier: Apache-2.0
27+
//
28+
//===----------------------------------------------------------------------===//
29+
30+
internal extension UInt8 {
31+
@inlinable
32+
var isASCII: Bool {
33+
return self <= 127
34+
}
35+
}
36+
37+
internal extension String.UTF8View {
38+
/// Compares two UTF8 strings as case insensitive ASCII bytes.
39+
///
40+
/// - Parameter bytes: The string constant in the form of a collection of `UInt8`
41+
/// - Returns: Whether the collection contains **EXACTLY** this array or no, but by ignoring case.
42+
@inlinable
43+
func compareCaseInsensitiveASCIIBytes(to other: String.UTF8View) -> Bool {
44+
// fast path: we can get the underlying bytes of both
45+
let maybeMaybeResult = self.withContiguousStorageIfAvailable { lhsBuffer -> Bool? in
46+
other.withContiguousStorageIfAvailable { rhsBuffer in
47+
if lhsBuffer.count != rhsBuffer.count {
48+
return false
49+
}
50+
51+
for idx in 0 ..< lhsBuffer.count {
52+
// let's hope this gets vectorised ;)
53+
if lhsBuffer[idx] & 0xdf != rhsBuffer[idx] & 0xdf && lhsBuffer[idx].isASCII {
54+
return false
55+
}
56+
}
57+
return true
58+
}
59+
}
60+
61+
if let maybeResult = maybeMaybeResult, let result = maybeResult {
62+
return result
63+
} else {
64+
return self._compareCaseInsensitiveASCIIBytesSlowPath(to: other)
65+
}
66+
}
67+
68+
@inlinable
69+
@inline(never)
70+
func _compareCaseInsensitiveASCIIBytesSlowPath(to other: String.UTF8View) -> Bool {
71+
return self.elementsEqual(other, by: { return (($0 & 0xdf) == ($1 & 0xdf) && $0.isASCII) })
72+
}
73+
}
74+
75+
76+
internal extension String {
77+
@inlinable
78+
func isEqualCaseInsensitiveASCIIBytes(to: String) -> Bool {
79+
return self.utf8.compareCaseInsensitiveASCIIBytes(to: to.utf8)
80+
}
81+
}
82+

0 commit comments

Comments
 (0)