Skip to content

Commit 7dd6741

Browse files
committed
Expose PGPOnePassSignature.isEncapsulating()
This method exposes the nested flag of OnePassSignatures. Since the naming was a bit confusing, I renamed the flag to isEncapsulating. Exposing this flag to consumers is required for consumers to verify the signature properly. Before this change, consumers would need to encode the signature and access the correct byte to check the flag.
1 parent 9bba011 commit 7dd6741

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

pg/src/main/java/org/bouncycastle/bcpg/OnePassSignaturePacket.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class OnePassSignaturePacket
1414
private int hashAlgorithm;
1515
private int keyAlgorithm;
1616
private long keyID;
17-
private int nested;
17+
private int isEncapsulating;
1818

1919
OnePassSignaturePacket(
2020
BCPGInputStream in)
@@ -34,7 +34,7 @@ public class OnePassSignaturePacket
3434
keyID |= (long)in.read() << 8;
3535
keyID |= in.read();
3636

37-
nested = in.read();
37+
isEncapsulating = in.read();
3838
}
3939

4040
public OnePassSignaturePacket(
@@ -49,7 +49,7 @@ public OnePassSignaturePacket(
4949
this.hashAlgorithm = hashAlgorithm;
5050
this.keyAlgorithm = keyAlgorithm;
5151
this.keyID = keyID;
52-
this.nested = (isNested) ? 0 : 1;
52+
this.isEncapsulating = (isNested) ? 0 : 1;
5353
}
5454

5555
/**
@@ -84,6 +84,17 @@ public long getKeyID()
8484
{
8585
return keyID;
8686
}
87+
88+
/**
89+
* Return true, if the signature is encapsulating.
90+
* An encapsulating OPS is followed by additional OPS packets and is calculated over all the data between itself
91+
* and its corresponding signature (it is an attestation for encapsulated signatures).
92+
*
93+
* @return true if encapsulating, false otherwise
94+
*/
95+
public boolean isEncapsulating() {
96+
return isEncapsulating == 1;
97+
}
8798

8899
/**
89100
*
@@ -109,7 +120,7 @@ public void encode(
109120
pOut.write((byte)(keyID >> 8));
110121
pOut.write((byte)(keyID));
111122

112-
pOut.write(nested);
123+
pOut.write(isEncapsulating);
113124

114125
pOut.close();
115126

pg/src/main/java/org/bouncycastle/openpgp/PGPOnePassSignature.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,17 @@ public int getKeyAlgorithm()
203203
return sigPack.getKeyAlgorithm();
204204
}
205205

206+
/**
207+
* Return true, if the signature is encapsulating.
208+
* An encapsulating OPS is followed by additional OPS packets and is calculated over all the data between itself
209+
* and its corresponding signature (it is an attestation for encapsulated signatures).
210+
*
211+
* @return true if encapsulating, false otherwise
212+
*/
213+
public boolean isEncapsulating() {
214+
return sigPack.isEncapsulating();
215+
}
216+
206217
public byte[] getEncoded()
207218
throws IOException
208219
{

0 commit comments

Comments
 (0)