From 52327a7cfef7837f5464f04f1fd681998e7a7ed2 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Mon, 6 Mar 2023 23:30:06 +0700 Subject: Refactoring in OpenPgp --- crypto/src/openpgp/PgpCompressedData.cs | 7 +++---- crypto/src/openpgp/PgpLiteralData.cs | 7 +++---- crypto/src/openpgp/PgpMarker.cs | 7 +++---- crypto/src/openpgp/PgpPublicKeyRing.cs | 4 ++-- 4 files changed, 11 insertions(+), 14 deletions(-) (limited to 'crypto/src/openpgp') diff --git a/crypto/src/openpgp/PgpCompressedData.cs b/crypto/src/openpgp/PgpCompressedData.cs index 346b0b1a1..b06f9bcaa 100644 --- a/crypto/src/openpgp/PgpCompressedData.cs +++ b/crypto/src/openpgp/PgpCompressedData.cs @@ -10,14 +10,13 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp { private readonly CompressedDataPacket data; - public PgpCompressedData( - BcpgInputStream bcpgInput) + public PgpCompressedData(BcpgInputStream bcpgInput) { Packet packet = bcpgInput.ReadPacket(); - if (!(packet is CompressedDataPacket)) + if (!(packet is CompressedDataPacket compressedDataPacket)) throw new IOException("unexpected packet in stream: " + packet); - this.data = (CompressedDataPacket)packet; + this.data = compressedDataPacket; } /// The algorithm used for compression diff --git a/crypto/src/openpgp/PgpLiteralData.cs b/crypto/src/openpgp/PgpLiteralData.cs index d1b7b4a4d..92fafe657 100644 --- a/crypto/src/openpgp/PgpLiteralData.cs +++ b/crypto/src/openpgp/PgpLiteralData.cs @@ -18,14 +18,13 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp private readonly LiteralDataPacket data; - public PgpLiteralData( - BcpgInputStream bcpgInput) + public PgpLiteralData(BcpgInputStream bcpgInput) { Packet packet = bcpgInput.ReadPacket(); - if (!(packet is LiteralDataPacket)) + if (!(packet is LiteralDataPacket literalDataPacket)) throw new IOException("unexpected packet in stream: " + packet); - this.data = (LiteralDataPacket)packet; + this.data = literalDataPacket; } /// The format of the data stream - Binary or Text diff --git a/crypto/src/openpgp/PgpMarker.cs b/crypto/src/openpgp/PgpMarker.cs index 7257767ec..fdbc02bc1 100644 --- a/crypto/src/openpgp/PgpMarker.cs +++ b/crypto/src/openpgp/PgpMarker.cs @@ -12,14 +12,13 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp { private readonly MarkerPacket data; - public PgpMarker( - BcpgInputStream bcpgInput) + public PgpMarker(BcpgInputStream bcpgInput) { Packet packet = bcpgInput.ReadPacket(); - if (!(packet is MarkerPacket)) + if (!(packet is MarkerPacket markerPacket)) throw new IOException("unexpected packet in stream: " + packet); - this.data = (MarkerPacket)packet; + this.data = markerPacket; } } } diff --git a/crypto/src/openpgp/PgpPublicKeyRing.cs b/crypto/src/openpgp/PgpPublicKeyRing.cs index e1a2a83f2..34b9e34d1 100644 --- a/crypto/src/openpgp/PgpPublicKeyRing.cs +++ b/crypto/src/openpgp/PgpPublicKeyRing.cs @@ -185,10 +185,10 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp internal static PublicKeyPacket ReadPublicKeyPacket(BcpgInputStream bcpgInput) { Packet packet = bcpgInput.ReadPacket(); - if (!(packet is PublicKeyPacket)) + if (!(packet is PublicKeyPacket publicKeyPacket)) throw new IOException("unexpected packet in stream: " + packet); - return (PublicKeyPacket)packet; + return publicKeyPacket; } internal static PgpPublicKey ReadSubkey(BcpgInputStream bcpgInput) -- cgit 1.4.1