@@ -7,6 +7,7 @@ use bstr::{BStr, ByteSlice};
7
7
use btoi:: btoi;
8
8
use hex:: FromHex ;
9
9
use nom:: bytes:: complete:: { is_not, take_till} ;
10
+ use nom:: combinator:: { all_consuming, recognize} ;
10
11
use nom:: sequence:: delimited;
11
12
use nom:: {
12
13
branch:: alt,
@@ -167,7 +168,7 @@ pub(crate) fn parse_tag_nom(i: &[u8]) -> IResult<&[u8], Tag, Error> {
167
168
168
169
let ( i, signature) = terminated ( preceded ( tag ( b"tagger " ) , parse_signature_nom) , tag ( NL ) ) ( i)
169
170
. map_err ( Error :: context ( "tagger <signature>" ) ) ?;
170
- let ( i, ( message, pgp_signature) ) = parse_message_nom ( i) ?;
171
+ let ( i, ( message, pgp_signature) ) = all_consuming ( parse_message_nom) ( i) ?;
171
172
Ok ( (
172
173
i,
173
174
Tag {
@@ -182,9 +183,8 @@ pub(crate) fn parse_tag_nom(i: &[u8]) -> IResult<&[u8], Tag, Error> {
182
183
}
183
184
184
185
pub ( crate ) fn parse_message_nom ( i : & [ u8 ] ) -> IResult < & [ u8 ] , ( & BStr , Option < & BStr > ) , Error > {
185
- let NLNL : & [ u8 ] = b"\n \n " ;
186
- const PGP_SIGNATURE_BEGIN : & [ u8 ] = b"-----BEGIN PGP SIGNATURE-----" ;
187
- const PGP_SIGNATURE_END : & [ u8 ] = b"-----END PGP SIGNATURE-----" ;
186
+ const PGP_SIGNATURE_BEGIN : & [ u8 ] = b"\n -----BEGIN PGP SIGNATURE-----" ;
187
+ const PGP_SIGNATURE_END : & [ u8 ] = b"-----END PGP SIGNATURE-----\n " ;
188
188
189
189
let ( i, _) = tag ( NL ) ( i) ?;
190
190
if i. is_empty ( ) {
@@ -197,16 +197,23 @@ pub(crate) fn parse_message_nom(i: &[u8]) -> IResult<&[u8], (&BStr, Option<&BStr
197
197
"tag message is missing" ,
198
198
) ) ) ;
199
199
}
200
- tag ( NL ) ( & i[ i. len ( ) - 1 ..] ) . map_err ( Error :: context ( "tag message must end with newline" ) ) ?;
201
- Ok ( ( & [ ] , ( & i[ ..i. len ( ) - 1 ] , & [ ] ) ) )
200
+ let ( i, _) = tag ( NL ) ( & i[ i. len ( ) - 1 ..] )
201
+ . map_err ( Error :: context ( "tag message must end with newline" ) ) ?;
202
+ // an empty signature message signals that there is none - the function signature is needed
203
+ // to work with 'alt(…)'. PGP signatures are never empty
204
+ Ok ( ( i, ( & i[ ..i. len ( ) - 1 ] , & [ ] ) ) )
202
205
}
203
206
let ( i, ( message, signature) ) = alt ( (
204
207
tuple ( (
205
208
take_until ( PGP_SIGNATURE_BEGIN ) ,
206
209
delimited (
207
- tag ( PGP_SIGNATURE_BEGIN ) ,
208
- take_until ( PGP_SIGNATURE_END ) ,
209
- tag ( PGP_SIGNATURE_END ) ,
210
+ tag ( NL ) ,
211
+ recognize ( delimited (
212
+ tag ( & PGP_SIGNATURE_BEGIN [ 1 ..] ) ,
213
+ take_until ( PGP_SIGNATURE_END ) ,
214
+ tag ( & PGP_SIGNATURE_END [ ..PGP_SIGNATURE_END . len ( ) - 1 ] ) ,
215
+ ) ) ,
216
+ tag ( NL ) ,
210
217
) ,
211
218
) ) ,
212
219
all_but_trailing_newline,
0 commit comments