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

ISSUE-4-add-original-file-name-to-encrypted-message (#1) #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/kotlin/KotlinPGP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ object KotlinPGP {
armoredOutputStream.setHeader(head.key, head.value)
}
val messageBytes = encryptParameter.message.toByteArray()
val messageName = encryptParameter.messageOriginatingFileName.ifEmpty { PGPLiteralData.CONSOLE }
val signatureGenerator: PGPSignatureGenerator?
var signatureHashAlgorithm = 0
if (encryptParameter.enableSignature) {
Expand Down Expand Up @@ -428,7 +429,7 @@ object KotlinPGP {
val literalDataGeneratorOutput = literalDataGenerator.open(
bcpgOutputStream,
PGPLiteralData.UTF8,
PGPLiteralData.CONSOLE,
messageName,
Date(),
ByteArray(1 shl 16)
)
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/data/EncryptParameter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ data class EncryptParameter(
val enableSignature: Boolean = false,
val privateKey: String = "",
val password: String = "",
val compressionAlgorithm: Int = CompressionAlgorithmTags.ZIP
val compressionAlgorithm: Int = CompressionAlgorithmTags.ZIP,
val messageOriginatingFileName: String = ""
)

data class PublicKeyData(
Expand All @@ -19,4 +20,4 @@ data class PublicKeyData(
data class PrivateKeyData(
val key: String,
val password: String
)
)
12 changes: 11 additions & 1 deletion src/test/kotlin/KotlinPGPTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ class KotlinPGPTest : FreeSpec({
it.isPGPMessage
}
}
"encrypt data with originating filename" {
val encryptResult = KotlinPGP.encrypt(EncryptParameter(
message = contentToEncrypt,
publicKey = publicKeys,
messageOriginatingFileName = "test"
))
encryptResult should {
it.isPGPMessage
}
}
"decrypt" - {
val encryptedData = KotlinPGP.encrypt(EncryptParameter(
message = contentToEncrypt,
Expand Down Expand Up @@ -315,4 +325,4 @@ private fun testKeyPair(keypair: PGPKeyPairData) {
keypair.secretKey should {
it.isPGPPrivateKey
}
}
}