summary refs log tree commit diff
path: root/crypto/src/cms/RecipientId.cs
blob: c4107b14e8fe972ff8d756cc0e4b9bce51d58685 (plain) (blame)
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
using System;

using Org.BouncyCastle.Utilities;
using Org.BouncyCastle.X509.Store;

namespace Org.BouncyCastle.Cms
{
    // TODO[api] sealed
    public class RecipientID
        : X509CertStoreSelector, IEquatable<RecipientID>
    {
        private byte[] m_keyIdentifier;

		public byte[] KeyIdentifier
		{
			get { return Arrays.Clone(m_keyIdentifier); }
			set { m_keyIdentifier = Arrays.Clone(value); }
		}

        public virtual bool Equals(RecipientID other)
        {
            return other == null ? false
                :  other == this ? true
                :  Arrays.AreEqual(m_keyIdentifier, other.m_keyIdentifier)
                && MatchesSubjectKeyIdentifier(other)
                && MatchesSerialNumber(other)
                && MatchesIssuer(other);
        }

        public override bool Equals(object obj) => Equals(obj as RecipientID);

        public override int GetHashCode()
        {
            return Arrays.GetHashCode(m_keyIdentifier)
				^  GetHashCodeOfSubjectKeyIdentifier()
                ^  Objects.GetHashCode(SerialNumber)
                ^  Objects.GetHashCode(Issuer);
        }
    }
}