summary refs log tree commit diff
path: root/crypto/src/tls/crypto/impl/AbstractTlsCipher.cs
blob: 5315eb96510d607354c688573bbf0fcfbee655db (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;

using Org.BouncyCastle.Utilities.IO.Compression;

namespace Org.BouncyCastle.Tls.Crypto.Impl
{
    public abstract class AbstractTlsCipher
        : TlsCipher
    {
        public abstract int GetCiphertextDecodeLimit(int plaintextLimit);

        public abstract int GetCiphertextEncodeLimit(int plaintextLength, int plaintextLimit);

        // TODO[api] Remove this method from TlsCipher
        public virtual int GetPlaintextLimit(int ciphertextLimit)
        {
            return GetPlaintextEncodeLimit(ciphertextLimit);
        }

        // TODO[api] Add to TlsCipher
        public virtual int GetPlaintextDecodeLimit(int ciphertextLimit)
        {
            return GetPlaintextLimit(ciphertextLimit);
        }

        // TODO[api] Add to TlsCipher
        public virtual int GetPlaintextEncodeLimit(int ciphertextLimit)
        {
            return GetPlaintextLimit(ciphertextLimit);
        }

        public abstract TlsEncodeResult EncodePlaintext(long seqNo, short contentType, ProtocolVersion recordVersion,
            int headerAllocation, byte[] plaintext, int offset, int len);

#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
        public abstract TlsEncodeResult EncodePlaintext(long seqNo, short contentType, ProtocolVersion recordVersion,
            int headerAllocation, ReadOnlySpan<byte> plaintext);
#endif

        // TODO[api] Add span-based version?
        public abstract TlsDecodeResult DecodeCiphertext(long seqNo, short recordType, ProtocolVersion recordVersion,
            byte[] ciphertext, int offset, int len);

        public virtual void RekeyDecoder()
        {
            throw new TlsFatalAlert(AlertDescription.internal_error);
        }

        public virtual void RekeyEncoder()
        {
            throw new TlsFatalAlert(AlertDescription.internal_error);
        }

        public abstract bool UsesOpaqueRecordType { get; }
    }
}