Skip to content

SQLiteCipher NSData key support #172

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

Closed
wants to merge 4 commits into from
Closed

SQLiteCipher NSData key support #172

wants to merge 4 commits into from

Conversation

agisboye
Copy link
Collaborator

@agisboye agisboye commented Aug 8, 2015

Adds key and rekey methods that accept a key of type NSData.
This allows the database to be easily keyed with a key generated by
Security.framework:

let keyData = NSMutableData(length: 64)!
let result = SecRandomCopyBytes(kSecRandomDefault, 64,
UnsafeMutablePointer<UInt8>(keyData.mutableBytes))

db.key(keyData)

agisboye added 3 commits August 7, 2015 11:23
Adds key and rekey methods that accept a key of type NSData.
This allows the database to be easily keyed with a key generated by
Security.framework:

let keyData = NSMutableData(length: 64)!
let result = SecRandomCopyBytes(kSecRandomDefault, 64,
UnsafeMutablePointer<UInt8>(keyData.mutableBytes))

db.key(keyData)
@stephencelis
Copy link
Owner

Thanks for the pull request! A few small things and I'd love to merge this.

  • I've been trying to segregate Foundation code wherever possible to keep SQLite.swift as portable as possible (especially since Swift will be on Linux in the future, but Foundation may not be). Any chance you can use SQLite.Blob, instead?
  • Would you please maintain the whitespace of the original file? It looks like your lines use tabs, but the rest of the project uses 4 spaces.
  • Would you write a quick couple tests for the cipher target? They should basically match the other two tests.

@stephencelis
Copy link
Owner

@agisboye Any update here? If you don't want to make the changes I'll try to implement them when I have the chance.

@agisboye
Copy link
Collaborator Author

@stephencelis Sorry for the delay. I've switched to SQLite.Blob and fixed the whitespace. I haven't gotten around to the tests yet I'm afraid.

@stephencelis
Copy link
Owner

Looking good! Let me know if you need any direction getting some tests written!

@@ -62,6 +62,10 @@ public struct Blob {
public init(bytes: UnsafePointer<Void>, length: Int) {
data = NSData(bytes: bytes, length: length)
}

public init (data: NSData) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance we can get rid of this convenience initializer? The swift-2 branch actually uses a fully Swift implementation of Blob (no reliance on Foundation/NSData), which I may back-port, at which point you can still create a blob from NSData like this:

// data: NSData
let blob = Blob(bytes: data.bytes, length: data.length)

@stephencelis
Copy link
Owner

Any update here? Would love to merge this if you have time to add some tests!

@agisboye
Copy link
Collaborator Author

I've added tests, but I had to submit a new pull request (#317). Go ahead and remove this PR (#172).

@stephencelis
Copy link
Owner

Closing in favor of #317.

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