-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix over-iterating buffer in hex string utility. #141
base: main
Are you sure you want to change the base?
Conversation
Can one of the admins verify this patch? |
6 similar comments
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! One minor tweak in the compiler defines and we should be go.
import XCTest | ||
|
||
// Not sure if NSString-bridged "String.init(format:_:)" is available on Linux/Windows. | ||
#if (os(macOS) || os(iOS) || os(tvOS) || os(watchOS)) && CRYPTO_IN_SWIFTPM_FORCE_BUILD_API |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this line needs to be:
#if (os(macOS) || os(iOS) || os(watchOS) || os(tvOS)) && CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API
// Skip tests that require @testable imports of CryptoKit.
#else
#if (os(macOS) || os(iOS) || os(watchOS) || os(tvOS)) && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API
@testable import CryptoKit
#else
@testable import Crypto
#endif
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did look at what other tests wrote. But I wasn't checking whether to use CryptoKit
or Crypto
, rather I needed to know (guess) whether String.init(format:_:)
was available in the SDK. On appleOS this API is provided for sure by bridging from NSString
's initializer, but on Linux and Windows I couldn't know.
The code you suggested would make this test always available cross-platform. Let me verify if Swift's cross-platform Foundation
port has this API. Otherwise I'll need to do something like sprintf
to make it cross-platform.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also CryptoTests
defines its own copy of PrettyBytes
. It's weird because I though @testable import
means that test target has access to everything non-private in the original Crypto
module.
This would mean the PrettyBytesTests
does not actually need to import anything, as the test only tests functions defined in the test target itself.
Can you clarify this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with only testing the one in the tests module, tbh.
Fixes #139: over-iteration in hex string.
Checklist
If you've made changes to
gyb
files.script/generate_boilerplate_files_with_gyb
and included updated generated files in a commit of this pull requestMotivation:
Upon discussing it in #139, an issue was identified that could cause unexpected hex output for a data buffer whose memory spans multiple non-contiguous regions.
Modifications:
Removed memory region specific logic. Fix applied to 3 copies of the same function.
Also added unit test on Apple platforms to compare with
NSString
's hex output.Result:
With multi-region
DataProtocol
s,hexString
should return correct hex.