66 lines
No EOL
1.6 KiB
C#
66 lines
No EOL
1.6 KiB
C#
using System.Security.Cryptography;
|
|
using FrostFS.SDK.ModelsV2.Enums;
|
|
|
|
namespace FrostFS.SDK.ModelsV2;
|
|
|
|
public class Object
|
|
{
|
|
public Object()
|
|
{
|
|
}
|
|
|
|
public Object(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; set; }
|
|
public byte[] Payload { get; set; }
|
|
public Signature Signature { get; set; }
|
|
|
|
public void SetParent(LargeObject largeObject)
|
|
{
|
|
Header.Split.ParentHeader = largeObject.Header;
|
|
}
|
|
|
|
public ObjectId? GetParentId()
|
|
{
|
|
return Header.Split?.Parent;
|
|
}
|
|
}
|
|
|
|
public class LargeObject(ContainerId container) : Object(container, [])
|
|
{
|
|
private 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 : Object
|
|
{
|
|
public LinkObject(ContainerId containerId, SplitId splitId, LargeObject largeObject) : base (containerId, [])
|
|
{
|
|
Header.Split = new Split(splitId)
|
|
{
|
|
ParentHeader = largeObject.Header
|
|
};
|
|
}
|
|
} |