Skip to content

Instantly share code, notes, and snippets.

@andreis
Last active August 29, 2015 14:08
Show Gist options
  • Save andreis/58040ef0e6523773e606 to your computer and use it in GitHub Desktop.
Save andreis/58040ef0e6523773e606 to your computer and use it in GitHub Desktop.
func Encrypt(string text, string[] publicKeys) (string, error) {
// string is the encrypted text
// error is null if encryption went OK, or non-null when there was an error
// (e.g. one of the public keys wasn't well formatted)
// (http://stackoverflow.com/questions/2341486/how-are-pgp-keys-formatted)
}
func Decrypt(string text, string privateKey) (string, error) {
// string is the decrypted text
// error is null if decryption went OK, or non-null when there was an error
// (e.g. the private key is not valid, or is not the correct one)
}
var TestMe = "Who let the dogs out"
var TestMeLarge = GetTextFromURL("http://example.com/really_long_text.txt")
// type PGPKey = {string pub, string priv}
var PGPKeys = MakePGPKeys(10) // makes an array of type PGPKey
var OtherPGPKey = MakePGPKey() // makes a single PGPKey object
// Optionally split this into EncryptTest and DecryptTest to test the methods separately
func CryptoTest() {
var Correct = Encrypt(TestMe, PGPKeys) // assume you can pass both arrays and elements
var CorrectLarge = Encrypt(TestMeLarge, PGPKeys)
var Incorrect = Encrypt(TestMe, OtherPGPKey)
test.AssertEquals(Decrypt(Correct, PGPKeys[0]), TestMe)
test.AssertEquals(Decrypt(CorrectLarge, PGPKeys[0]), TestMeLarge)
test.AssertTrue(Decrypt(Incorrect, PGPKeys[0]) != TestMe) // this wasn't encrypted with PGPKeys[0]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment