Skip to content
This repository was archived by the owner on Aug 24, 2021. It is now read-only.

Commit b6b60ae

Browse files
committed
GPG signature parsing
1 parent eafeffc commit b6b60ae

23 files changed

+47
-18
lines changed

src/util/commit.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@ exports.serialize = (dagNode, callback) => {
1414
})
1515
lines.push('author ' + gitUtil.serializePersonLine(dagNode.author))
1616
lines.push('committer ' + gitUtil.serializePersonLine(dagNode.committer))
17-
if (dagNode.encoding !== undefined) {
17+
if (dagNode.encoding) {
1818
lines.push('encoding ' + dagNode.encoding)
1919
}
20+
if (dagNode.signature) {
21+
lines.push('gpgsig -----BEGIN PGP SIGNATURE-----')
22+
lines.push(dagNode.signature.text)
23+
lines.push(' -----END PGP SIGNATURE-----')
24+
}
2025
lines.push('')
2126
lines.push(dagNode.message)
2227

@@ -38,7 +43,7 @@ exports.deserialize = (data, callback) => {
3843
let m = lines[line].match(/^([^ ]+) (.+)$/)
3944
if (!m) {
4045
if (lines[line] !== '') {
41-
setImmediate(() => callback(new Error('Invalid tag line ' + line)))
46+
setImmediate(() => callback(new Error('Invalid commit line ' + line)))
4247
}
4348
res.message = lines.slice(line + 1).join('\n')
4449
break
@@ -59,6 +64,22 @@ exports.deserialize = (data, callback) => {
5964
case 'parent':
6065
res.parents.push({'/': gitUtil.shaToCid(new Buffer(value, 'hex'))})
6166
break
67+
case 'gpgsig': {
68+
if (value !== '-----BEGIN PGP SIGNATURE-----') {
69+
setImmediate(() => callback(new Error('Invalid commit line ' + line)))
70+
}
71+
res.signature = {}
72+
73+
let startLine = line
74+
for (; line < lines.length - 1; line++) {
75+
if (lines[line + 1] === ' -----END PGP SIGNATURE-----') {
76+
res.signature.text = lines.slice(startLine + 1, line + 1).join('\n')
77+
break
78+
}
79+
}
80+
line++
81+
break
82+
}
6283
default:
6384
res[key] = value
6485
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

test/fixtures/70ce33c808791776ea89c98bb28bdab6352fc6e3

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
x���
2+
!�;�s�R����ԩKϠ���.b���R�^����3�9�[i�"�Z�}�:Bˣ2Qj5PI�h����fWh��B��Qt�� ��Jx�=:E�Y�u�.y��� ֟x�#�����ri~�s�������U�W6\r��p��6�?���}{3�^J

test/fixtures/8b2f5644236ae7d01cb373c9b8ad70bc3da01393

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)