| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | |
| | | 6 | | namespace CoreWCF.Security |
| | | 7 | | { |
| | | 8 | | internal class SignatureConfirmations |
| | | 9 | | { |
| | | 10 | | private SignatureConfirmation[] _confirmations; |
| | | 11 | | |
| | | 12 | | private struct SignatureConfirmation |
| | | 13 | | { |
| | | 14 | | private byte[] _value; |
| | | 15 | | |
| | | 16 | | public SignatureConfirmation(byte[] value) |
| | | 17 | | { |
| | 0 | 18 | | _value = value; |
| | 0 | 19 | | } |
| | | 20 | | |
| | 0 | 21 | | public byte[] Value { get => _value; set => _value = value; } |
| | | 22 | | } |
| | | 23 | | |
| | 0 | 24 | | public SignatureConfirmations() |
| | | 25 | | { |
| | 0 | 26 | | _confirmations = new SignatureConfirmation[1]; |
| | 0 | 27 | | Count = 0; |
| | 0 | 28 | | } |
| | | 29 | | |
| | 0 | 30 | | public int Count { get; private set; } |
| | | 31 | | |
| | | 32 | | public void AddConfirmation(byte[] value, bool encrypted) |
| | | 33 | | { |
| | 0 | 34 | | if (_confirmations.Length == Count) |
| | | 35 | | { |
| | 0 | 36 | | SignatureConfirmation[] newConfirmations = new SignatureConfirmation[Count * 2]; |
| | 0 | 37 | | Array.Copy(_confirmations, 0, newConfirmations, 0, Count); |
| | 0 | 38 | | _confirmations = newConfirmations; |
| | | 39 | | } |
| | 0 | 40 | | _confirmations[Count] = new SignatureConfirmation(value); |
| | 0 | 41 | | ++Count; |
| | 0 | 42 | | IsMarkedForEncryption |= encrypted; |
| | 0 | 43 | | } |
| | | 44 | | |
| | | 45 | | public void GetConfirmation(int index, out byte[] value, out bool encrypted) |
| | | 46 | | { |
| | 0 | 47 | | if (index < 0 || index >= Count) |
| | | 48 | | { |
| | 0 | 49 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(index), |
| | | 50 | | } |
| | | 51 | | |
| | 0 | 52 | | value = _confirmations[index].Value; |
| | 0 | 53 | | encrypted = IsMarkedForEncryption; |
| | 0 | 54 | | } |
| | | 55 | | |
| | 0 | 56 | | public bool IsMarkedForEncryption { get; private set; } |
| | | 57 | | } |
| | | 58 | | } |