Skip to content
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

Changes InternalExtensions to NSData+Extensions #21

Merged
merged 1 commit into from
Jan 21, 2016

Conversation

brunokoga
Copy link
Contributor

  • The NSData and NSMutableData are now public (That's why I renamed the
    file)
  • With this change, whenever we need to extend the lib, we can use the
    same methods as Sodium to access the data pointers instead needing to
    duplicate this code.

- The NSData and NSMutableData are now public (That's why I renamed the
  file)
- With this change, whenever we need to extend the lib, we can use the
  same methods as Sodium to access the data pointers instead needing to
  duplicate this code.
@brunokoga
Copy link
Contributor Author

Here is one example. To achieve this, I needed to duplicate the NSData/NSMutableData extensions to my own module.

extension SecretBox {
    public func seal(message: NSData, secretKey: Key, nonce: NSData) -> NSData? {
        if secretKey.length != KeyBytes {
            return nil
        }
        guard let authenticatedCipherText = NSMutableData(length: message.length + MacBytes) else {
            return nil
        }
        if crypto_secretbox_easy(authenticatedCipherText.mutableBytesPtr, message.bytesPtr, UInt64(message.length), nonce.bytesPtr, secretKey.bytesPtr) != 0 {
            return nil
        }
        return authenticatedCipherText
    }
}

@jedisct1
Copy link
Owner

Looks good and useful!

Merged, thanks!

jedisct1 added a commit that referenced this pull request Jan 21, 2016
Changes `InternalExtensions` to `NSData+Extensions`
@jedisct1 jedisct1 merged commit c03f6ad into jedisct1:master Jan 21, 2016
@brunokoga
Copy link
Contributor Author

man, you're fast. :)

@jedisct1
Copy link
Owner

:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants