using System; using System.Security.Cryptography; using FrostFS.SDK.ModelsV2.Enums; namespace FrostFS.SDK.ModelsV2; public class FrostFsObject { public FrostFsObject(ObjectId objectId, ObjectHeader header, byte[] payload) { ObjectId = objectId; Payload = payload; Header = header; } public FrostFsObject(ContainerId container, byte[] payload, ObjectType objectType = ObjectType.Regular) { Payload = payload; Header = new ObjectHeader(containerId: container, type: objectType, attributes: []); } public ObjectHeader Header { get; set; } public ObjectId? ObjectId { get; internal set; } public byte[] Payload { get; set; } public IObjectReader? ObjectReader { get; set; } public Signature? Signature { get; set; } public void SetParent(LargeObject largeObject) { if (Header?.Split == null) throw new Exception("The object is not initialized properly"); Header.Split.ParentHeader = largeObject.Header; } } public class LargeObject(ContainerId container) : FrostFsObject(container, []) { private readonly SHA256 payloadHash = SHA256.Create(); public void AppendBlock(byte[] bytes, int count) { Header!.PayloadLength += (ulong)count; this.payloadHash.TransformBlock(bytes, 0, count, bytes, 0); } public LargeObject CalculateHash() { this.payloadHash.TransformFinalBlock([], 0, 0); Header!.PayloadCheckSum = this.payloadHash.Hash; return this; } public ulong PayloadLength { get { return Header!.PayloadLength; } } } public class LinkObject : FrostFsObject { public LinkObject(ContainerId containerId, SplitId splitId, LargeObject largeObject) : base (containerId, []) { Header!.Split = new Split(splitId) { ParentHeader = largeObject.Header }; } }