8000 Refactor - Phase 1 · openssl-net/openssl-net@f8dfbc1 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit f8dfbc1

Browse files
author
Adam Caudill
committed
Refactor - Phase 1
This is a cleanup of formatting, style, etc. - there are no functional changes.
1 parent 2f8abc2 commit f8dfbc1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2231
-2065
lines changed

ManagedOpenSsl/Core/Asn1DateTime.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2525

2626
using System;
27-
using System.Collections.Generic;
28-
using System.Text;
2927
using System.Globalization;
3028

3129
namespace OpenSSL.Core
@@ -48,19 +46,19 @@ public Asn1DateTime(DateTime dateTime)
4846

4947
protected override void OnDispose()
5048
{
51-
Native.ASN1_TIME_free(this.ptr);
49+
Native.ASN1_TIME_free(ptr);
5250
}
5351

5452
public DateTime DateTime
5553
{
5654
get
5755
{
58-
return ToDateTime(this.ptr);
56+
return ToDateTime(ptr);
5957
}
6058
set
6159
{
62-
long time_t = DateTimeToTimeT(value.ToUniversalTime());
63-
Native.ASN1_TIME_set(this.ptr, time_t);
60+
var time_t = DateTimeToTimeT(value.ToUniversalTime());
61+
Native.ASN1_TIME_set(ptr, time_t);
6462
}
6563
}
6664

@@ -71,25 +69,30 @@ public static DateTime ToDateTime(IntPtr ptr)
7169

7270
private long DateTimeToTimeT(DateTime value)
7371
{
74-
DateTime dt1970 = new DateTime(1970, 1, 1, 0, 0, 0, 0);
72+
var dt1970 = new DateTime(1970, 1, 1, 0, 0, 0, 0);
73+
7574
// # of 100 nanoseconds since 1970
76-
long ticks = (value.Ticks - dt1970.Ticks) / 10000000L;
75+
var ticks = (value.Ticks - dt1970.Ticks) / 10000000L;
76+
7777
return ticks;
7878
}
7979

8080
private static DateTime AsnTimeToDateTime(IntPtr ptr)
8181
{
8282
string str;
83-
using (BIO bio = BIO.MemoryBuffer())
83+
84+
using (var bio = BIO.MemoryBuffer())
8485
{
8586
Native.ExpectSuccess(Native.ASN1_UTCTIME_print(bio.Handle, ptr));
8687
str = bio.ReadString();
8788
}
89+
8890
string[] fmts =
8991
{
9092
"MMM d HH:mm:ss yyyy G\\MT",
9193
"MMM dd HH:mm:ss yyyy G\\MT"
9294
};
95+
9396
return DateTime.ParseExact(str, fmts, new DateTimeFormatInfo(), DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
9497
}
9598
}

ManagedOpenSsl/Core/Asn1Integer.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2525

2626
using System;
27-
using System.Collections.Generic;
28-
using System.Text;
29-
using System.Globalization;
3027

3128
namespace OpenSSL.Core
3229
{
@@ -43,18 +40,18 @@ public Asn1Integer()
4340
public Asn1Integer(int value)
4441
: this()
4542
{
46-
this.Value = value;
43+
Value = value;
4744
}
4845

10000 4946
protected override void OnDispose()
5047
{
51-
Native.ASN1_TIME_free(this.ptr);
48+
Native.ASN1_TIME_free(ptr);
5249
}
5350

5451
public int Value
5552
{
56-
get { return Native.ASN1_INTEGER_get(this.ptr); }
57-
set { Native.ExpectSuccess(Native.ASN1_INTEGER_set(this.ptr, value)); }
53+
get { return Native.ASN1_INTEGER_get(ptr); }
54+
set { Native.ExpectSuccess(Native.ASN1_INTEGER_set(ptr, value)); }
5855
}
5956

6057
public static int ToInt32(IntPtr ptr)

ManagedOpenSsl/Core/Asn1Object.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2424
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2525

26-
using System;
2726
using System.Runtime.InteropServices;
2827

2928
namespace OpenSSL.Core
@@ -48,19 +47,19 @@ public Asn1Object(int nid) {
4847
}
4948

5049
public Asn1Object(string sn) {
51-
this.nid = Native.OBJ_sn2nid(sn);
50+
nid = Native.OBJ_sn2nid(sn);
5251
}
5352

5453
public int NID {
55-
get { return this.nid; }
54+
get { return nid; }
5655
}
5756

5857
public string ShortName {
59-
get { return Native.OBJ_nid2sn(this.nid); }
58+
get { return Native.OBJ_nid2sn(nid); }
6059
}
61 7802 60

6261
public string LongName {
63-
get { return Native.OBJ_nid2ln(this.nid); }
62+
get { return Native.OBJ_nid2ln(nid); }
6463
}
6564

6665
public static Asn1Object FromShortName(string sn) {
@@ -72,14 +71,16 @@ public static Asn1Object FromLongName(string sn) {
7271
}
7372

7473
public override bool Equals(object obj) {
75-
Asn1Object rhs = obj as Asn1Object;
74+
var rhs = obj as Asn1Object;
75+
7676
if (rhs == null)
7777
return false;
78-
return this.nid == rhs.nid;
78+
79+
return nid == rhs.nid;
7980
}
8081

8182
public override int GetHashCode() {
82-
return this.nid;
83+
return nid;
8384
}
8485
}
8586
}

ManagedOpenSsl/Core/Asn1String.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2525

2626
using System;
27-
using System.Collections.Generic;
28-
using System.Text;
2927
using System.Runtime.InteropServices;
3028

3129
namespace OpenSSL.Core
@@ -35,7 +33,7 @@ namespace OpenSSL.Core
3533
/// </summary>
3634
public class Asn1String : BaseValueType, IComparable<Asn1String>
3735
{
38-
#region Intialization
36+
#region Initialization
3937
/// <summary>
4038
/// Calls ASN1_STRING_type_new()
4139
/// </summary>
@@ -61,7 +59,7 @@ internal Asn1String(IntPtr ptr, bool takeOwnership)
6159
public Asn1String(byte[] data)
6260
: this()
6361
{
64-
Native.ExpectSuccess(Native.ASN1_STRING_set(this.ptr, data, data.Length));
62+
Native.ExpectSuccess(Native.ASN1_STRING_set(ptr, data, data.Length));
6563
}
6664
#endregion
6765

@@ -71,7 +69,7 @@ public Asn1String(byte[] data)
7169
/// </summary>
7270
public int Length
7371
{
74-
get { return Native.ASN1_STRING_length(this.ptr); }
72+
get { return Native.ASN1_STRING_length(ptr); }
7573
}
7674

7775
/// <summary>
@@ -81,9 +79,11 @@ public byte[] Data
8179
{
8280
get
8381
{
84-
IntPtr pData = Native.ASN1_STRING_data(this.ptr);
85-
byte[] ret = new byte[this.Length];
82+
var pData = Native.ASN1_STRING_data(ptr);
83+
var ret = new byte[Length];
84+
8685
Marshal.Copy(pData, ret, 0, ret.Length);
86+
8787
return ret;
8888
}
8989
}
@@ -93,15 +93,15 @@ public byte[] Data
9393

9494
internal override IntPtr DuplicateHandle()
9595
{
96-
return Native.ASN1_STRING_dup(this.ptr);
96+
return Native.ASN1_STRING_dup(ptr);
9797
}
9898

9999
/// <summary>
100100
/// Calls ASN1_STRING_free()
101101
/// </summary>
102102
protected override void OnDispose()
103103
{
104-
Native.ASN1_STRING_free(this.ptr);
104+
Native.ASN1_STRING_free(ptr);
105105
}
106106

107107
#endregion
@@ -115,7 +115,7 @@ protected override void OnDispose()
115115
/// <returns></returns>
116116
public int CompareTo(Asn1String other)
117117
{
118-
return Native.ASN1_STRING_cmp(this.ptr, other.Handle);
118+
return Native.ASN1_STRING_cmp(ptr, other.Handle);
119119
}
120120

121121
#endregion

0 commit comments

Comments
 (0)
0