public static Tag Deserialize(byte[] buffer, int offset, int count) { MemoryStream stream = new MemoryStream(buffer, offset, count); BinaryReader reader = new BinaryReader(stream); TagOptions options = new TagOptions(); byte version = reader.ReadByte(); if (version < MIN_VERSION || version > MAX_VERSION) { throw new InvalidOperationException("Invalid format version."); } options.NotBefore = DateTime.FromBinary(reader.ReadInt64()); options.NotAfter = DateTime.FromBinary(reader.ReadInt64()); options.SerialNumber = new Guid(reader.ReadBytes(16)); options.Qualifier = reader.ReadString(); bool isRoot = reader.ReadBoolean(); Entity issuer = Entity.Deserialize(DeserializeBytes(reader)); Entity holder = isRoot ? issuer : Entity.Deserialize(DeserializeBytes(reader)); byte[] signature = DeserializeBytes(reader); return(new Tag(issuer, holder, version, stream.ToArray(), signature, options)); }
private void ValidateOptions(TagOptions options) { if (options.Qualifier?.Length > MAX_QUALIFIER_LENGTH) { throw new ArgumentOutOfRangeException(nameof(options.Qualifier)); } }
public static Tag Create(Entity issuer, Entity holder, TagOptions options) { if (issuer == null) { throw new ArgumentNullException(nameof(issuer)); } if (holder == null) { throw new ArgumentNullException(nameof(holder)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (issuer.PublicOnly) { throw new ArgumentException("Entity must contain a private key.", nameof(issuer)); } return(new Tag(issuer, holder, MAX_VERSION, null, null, options)); }
private Tag(Entity issuer, Entity holder, byte version, byte[] rawData, byte[] signature, TagOptions options) { ValidateOptions(options); _issuer = issuer; _holder = holder; _version = version; _qualifier = options.Qualifier; _serialNumber = options.SerialNumber; _notAfter = options.NotAfter; _notBefore = options.NotBefore; _rawData = rawData; _signature = signature; }