Skip to content

Commit 51eb18b

Browse files
committed
use binary to preserve to line-endings
1 parent d8f75a3 commit 51eb18b

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@ async function run() {
4747
})
4848
}
4949
```
50+
51+
## Add your GPG key to github
52+
53+
see https://help.github.com/articles/adding-a-new-gpg-key-to-your-github-account/

index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,20 @@ async function sign({
3030
const privateKeyResult = (await openpgp.key.readArmored(privateKey)).keys[0]
3131
if (!privateKeyResult) throw new Error('unable to read private key')
3232
await privateKeyResult.decrypt(passphrase)
33+
34+
// use binary to preserve line-endings to make signatures match
35+
const buf = new Uint8Array(tosign.length)
36+
for (let i = 0; i < tosign.length; i++) {
37+
buf[i] = tosign.charCodeAt(i)
38+
}
39+
3340
const options = {
34-
message: openpgp.cleartext.fromText(tosign),
41+
message: openpgp.message.fromBinary(buf),
3542
privateKeys: [privateKeyResult],
3643
detached: true
3744
}
3845
const signed = await openpgp.sign(options)
39-
const signature = signed.signature.replace(/\r\n/g, '\n')
46+
const signature = signed.signature
4047
return signature
4148
}
4249
}

0 commit comments

Comments
 (0)