mirrored from https://www.bouncycastle.org/repositories/bc-csharp
-
Notifications
You must be signed in to change notification settings - Fork 602
Expand file tree
/
Copy pathPskIdentity.cs
More file actions
54 lines (43 loc) · 1.86 KB
/
Copy pathPskIdentity.cs
File metadata and controls
54 lines (43 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.IO;
using Org.BouncyCastle.Utilities;
namespace Org.BouncyCastle.Tls
{
public sealed class PskIdentity
{
private readonly byte[] m_identity;
private readonly long m_obfuscatedTicketAge;
public PskIdentity(byte[] identity, long obfuscatedTicketAge)
{
if (null == identity)
throw new ArgumentNullException(nameof(identity));
if (identity.Length < 1 || !TlsUtilities.IsValidUint16(identity.Length))
throw new ArgumentException("should have length from 1 to 65535", nameof(identity));
if (!TlsUtilities.IsValidUint32(obfuscatedTicketAge))
throw new ArgumentException("should be a uint32", nameof(obfuscatedTicketAge));
m_identity = identity;
m_obfuscatedTicketAge = obfuscatedTicketAge;
}
public int GetEncodedLength() => 6 + m_identity.Length;
public byte[] Identity => m_identity;
public long ObfuscatedTicketAge => m_obfuscatedTicketAge;
public void Encode(Stream output)
{
TlsUtilities.WriteOpaque16(Identity, output);
TlsUtilities.WriteUint32(ObfuscatedTicketAge, output);
}
public static PskIdentity Parse(Stream input)
{
byte[] identity = TlsUtilities.ReadOpaque16(input, 1);
long obfuscatedTicketAge = TlsUtilities.ReadUint32(input);
return new PskIdentity(identity, obfuscatedTicketAge);
}
public override bool Equals(object obj)
{
return obj is PskIdentity that
&& m_obfuscatedTicketAge == that.m_obfuscatedTicketAge
&& Arrays.FixedTimeEquals(m_identity, that.m_identity);
}
public override int GetHashCode() => Arrays.GetHashCode(m_identity) ^ m_obfuscatedTicketAge.GetHashCode();
}
}