File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -917,6 +917,16 @@ def sign(self, keyid: Optional[str] = None) -> None:
917
917
self .as_raw_string (), mode = gpg .constants .sig .mode .DETACH
918
918
)
919
919
920
+ def raw_without_sig (self ) -> bytes :
921
+ """Return raw string serialization without the GPG/SSH signature.
922
+
923
+ self.signature is a signature for the returned raw byte string serialization.
924
+ """
925
+ ret = self .as_raw_string ()
926
+ if self ._signature :
927
+ ret = ret [: - len (self ._signature )]
928
+ return ret
929
+
920
930
def verify (self , keyids : Optional [Iterable [str ]] = None ) -> None :
921
931
"""Verify GPG signature for this tag (if it is signed).
922
932
@@ -938,7 +948,7 @@ def verify(self, keyids: Optional[Iterable[str]] = None) -> None:
938
948
939
949
with gpg .Context () as ctx :
940
950
data , result = ctx .verify (
941
- self .as_raw_string ()[: - len ( self . _signature )] ,
951
+ self .raw_without_sig () ,
942
952
signature = self ._signature ,
943
953
)
944
954
if keyids :
Original file line number Diff line number Diff line change @@ -218,6 +218,7 @@ def test_read_tag_from_file(self) -> None:
218
218
b"=ql7y\n "
219
219
b"-----END PGP SIGNATURE-----\n " ,
220
220
)
221
+ self .assertEqual (t .raw_without_sig () + t .signature , bytes (t ))
221
222
222
223
def test_read_commit_from_file (self ) -> None :
223
224
sha = b"60dacdc733de308bb77bb76ce0fb0f9b44c9769e"
@@ -1238,6 +1239,23 @@ def test_tree_copy_after_update(self) -> None:
1238
1239
self .assertNotIn (shas [0 ], shas [1 :])
1239
1240
self .assertEqual (shas [1 ], shas [2 ])
1240
1241
1242
+ def test_tag_withough_sig (self ) -> None :
1243
+ x = Tag ()
1244
+ x .set_raw_string (self .make_tag_text ())
1245
+ self .assertEqual (bytes (x ), x .raw_without_sig () + x .signature )
1246
+ self .assertEqual (
1247
+ b"""\
1248
+ -----BEGIN PGP SIGNATURE-----
1249
+ Version: GnuPG v1.4.7 (GNU/Linux)
1250
+
1251
+ iD8DBQBGiAaAF3YsRnbiHLsRAitMAKCiLboJkQECM/jpYsY3WPfvUgLXkACgg3ql
1252
+ OK2XeQOiEeXtT76rV4t2WR4=
1253
+ =ivrA
1254
+ -----END PGP SIGNATURE-----
1255
+ """ ,
1256
+ x .signature ,
1257
+ )
1258
+
1241
1259
1242
1260
class CheckTests (TestCase ):
1243
1261
def test_check_hexsha (self ) -> None :
You can’t perform that action at this time.
0 commit comments