summary refs log tree commit diff
path: root/crypto/src/bcpg/ModDetectionCodePacket.cs
blob: 6bb23645a2fec6f6d93f55b2739678c51895dd9f (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
using System;
using System.IO;

namespace Org.BouncyCastle.Bcpg
{
	/// <remarks>Basic packet for a modification detection code packet.</remarks>
    public class ModDetectionCodePacket
        : ContainedPacket
    {
        private readonly byte[] digest;

		internal ModDetectionCodePacket(
            BcpgInputStream bcpgIn)
        {
			if (bcpgIn == null)
				throw new ArgumentNullException("bcpgIn");

			this.digest = new byte[20];
            bcpgIn.ReadFully(this.digest);
        }

		public ModDetectionCodePacket(
            byte[] digest)
        {
			if (digest == null)
				throw new ArgumentNullException("digest");

			this.digest = (byte[]) digest.Clone();
        }

		public byte[] GetDigest()
        {
			return (byte[]) digest.Clone();
        }

		public override void Encode(
            BcpgOutputStream bcpgOut)
        {
            bcpgOut.WritePacket(PacketTag.ModificationDetectionCode, digest, false);
        }
    }
}