Skip to content

Commit d497855

Browse files
committed
Misc. refactoring
1 parent b82448d commit d497855

File tree

7 files changed

+25
-37
lines changed

7 files changed

+25
-37
lines changed

crypto/src/asn1/x509/OtherName.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ namespace Org.BouncyCastle.Asn1.X509
1313
public class OtherName
1414
: Asn1Encodable
1515
{
16-
private readonly DerObjectIdentifier typeID;
17-
private readonly Asn1Encodable value;
18-
1916
/**
2017
* OtherName factory method.
2118
* @param obj the object used to construct an instance of <code>
@@ -29,13 +26,21 @@ public class OtherName
2926
*/
3027
public static OtherName GetInstance(object obj)
3128
{
32-
if (obj is OtherName)
33-
return (OtherName)obj;
3429
if (obj == null)
3530
return null;
31+
if (obj is OtherName otherName)
32+
return otherName;
3633
return new OtherName(Asn1Sequence.GetInstance(obj));
3734
}
3835

36+
public static OtherName GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
37+
{
38+
return GetInstance(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
39+
}
40+
41+
private readonly DerObjectIdentifier typeID;
42+
private readonly Asn1Encodable value;
43+
3944
/**
4045
* Base constructor.
4146
* @param typeID the type of the other name.
@@ -50,18 +55,12 @@ public OtherName(DerObjectIdentifier typeID, Asn1Encodable value)
5055
private OtherName(Asn1Sequence seq)
5156
{
5257
this.typeID = DerObjectIdentifier.GetInstance(seq[0]);
53-
this.value = DerTaggedObject.GetInstance(seq[1]).GetObject(); // explicitly tagged
58+
this.value = Asn1Utilities.GetExplicitContextBaseObject(Asn1TaggedObject.GetInstance(seq[1]), tagNo: 0);
5459
}
5560

56-
public virtual DerObjectIdentifier TypeID
57-
{
58-
get { return typeID; }
59-
}
61+
public virtual DerObjectIdentifier TypeID => typeID;
6062

61-
public Asn1Encodable Value
62-
{
63-
get { return value; }
64-
}
63+
public Asn1Encodable Value => value;
6564

6665
public override Asn1Object ToAsn1Object()
6766
{

crypto/src/crypto/engines/DesEdeEngine.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ public class DesEdeEngine
2121
* @exception ArgumentException if the parameters argument is
2222
* inappropriate.
2323
*/
24-
public override void Init(
25-
bool forEncryption,
26-
ICipherParameters parameters)
24+
public override void Init(bool forEncryption, ICipherParameters parameters)
2725
{
28-
if (!(parameters is KeyParameter))
29-
throw new ArgumentException("invalid parameter passed to DESede init - " + Platform.GetTypeName(parameters));
26+
if (!(parameters is KeyParameter keyParameter))
27+
throw new ArgumentException(
28+
"invalid parameter passed to DESede init - " + Platform.GetTypeName(parameters));
3029

31-
byte[] keyMaster = ((KeyParameter)parameters).GetKey();
30+
byte[] keyMaster = keyParameter.GetKey();
3231
if (keyMaster.Length != 24 && keyMaster.Length != 16)
3332
throw new ArgumentException("key size must be 16 or 24 bytes.");
3433

crypto/src/crypto/engines/RC4Engine.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,16 @@ public class RC4Engine
2828
* @exception ArgumentException if the parameters argument is
2929
* inappropriate.
3030
*/
31-
public virtual void Init(
32-
bool forEncryption,
33-
ICipherParameters parameters)
31+
public virtual void Init(bool forEncryption, ICipherParameters parameters)
3432
{
35-
if (parameters is KeyParameter)
33+
if (parameters is KeyParameter keyParameter)
3634
{
3735
/*
3836
* RC4 encryption and decryption is completely
3937
* symmetrical, so the 'forEncryption' is
4038
* irrelevant.
4139
*/
42-
workingKey = ((KeyParameter)parameters).GetKey();
40+
workingKey = keyParameter.GetKey();
4341
SetKey(workingKey);
4442

4543
return;

crypto/src/pkix/PkixCertPathValidatorUtilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ internal static void GetCrlIssuersFromDistributionPoint(
720720
// if (dp.getDistributionPoint() != null)
721721
// {
722722
// // look for nameRelativeToCRLIssuer
723-
// if (dp.getDistributionPoint().getType() == DistributionPointName.NAME_RELATIVE_TO_CRL_ISSUER)
723+
// if (dp.getDistributionPoint().Type == DistributionPointName.NAME_RELATIVE_TO_CRL_ISSUER)
724724
// {
725725
// // append fragment to issuer, only one
726726
// // issuer can be there, if this is given

crypto/src/x509/X509Crl.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -404,15 +404,7 @@ public override string ToString()
404404
* @return true if the given certificate is on this CRL,
405405
* false otherwise.
406406
*/
407-
// public bool IsRevoked(
408-
// Certificate cert)
409-
// {
410-
// if (!cert.getType().Equals("X.509"))
411-
// {
412-
// throw new RuntimeException("X.509 CRL used with non X.509 Cert");
413-
// }
414-
public virtual bool IsRevoked(
415-
X509Certificate cert)
407+
public virtual bool IsRevoked(X509Certificate cert)
416408
{
417409
CrlEntry[] certs = c.GetRevokedCertificates();
418410

crypto/test/src/tls/test/NetworkStream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private void CheckNotClosed()
9797
lock (this)
9898
{
9999
if (m_closed)
100-
throw new ObjectDisposedException(this.GetType().Name);
100+
throw new ObjectDisposedException(GetType().FullName);
101101
}
102102
}
103103
}

crypto/test/src/tls/test/PipedStream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ protected override void Dispose(bool disposing)
126126
private void CheckOpen()
127127
{
128128
if (m_closed)
129-
throw new ObjectDisposedException(this.GetType().Name);
129+
throw new ObjectDisposedException(GetType().FullName);
130130
}
131131

132132
private void WaitForData()

0 commit comments

Comments
 (0)