using System.Security.Cryptography; using FrostFS.Container; using FrostFS.Object; using FrostFS.SDK.ClientV2; using FrostFS.SDK.ClientV2.Mappers.GRPC; using FrostFS.SDK.Cryptography; using FrostFS.Session; using Google.Protobuf; using Grpc.Core; using Moq; namespace FrostFS.SDK.Tests; public abstract class ServiceBase(string key) { public string StringKey { get; private set; } = key; public ECDsa Key { get; private set; } = key.LoadWif(); public FrostFsVersion Version { get; set; } = DefaultVersion; public FrostFsPlacementPolicy PlacementPolicy { get; set; } = DefaultPlacementPolicy; public static FrostFsVersion DefaultVersion { get; } = new(2, 13); public static FrostFsPlacementPolicy DefaultPlacementPolicy { get; } = new FrostFsPlacementPolicy(true, new FrostFsReplica(1)); #pragma warning disable CA2227 // this is specific object, should be treated as is public Metadata? Metadata { get; set; } #pragma warning restore CA2227 public DateTime? DateTime { get; protected set; } public CancellationToken CancellationToken { get; protected set; } public CancellationTokenSource CancellationTokenSource { get; protected set; } = new CancellationTokenSource(); public static Metadata ResponseMetaData => []; protected ResponseVerificationHeader GetResponseVerificationHeader(IResponse response) { ArgumentNullException.ThrowIfNull(response); var verifyHeader = new ResponseVerificationHeader { MetaSignature = new Refs.Signature { Key = ByteString.CopyFrom(Key.PublicKey()), Scheme = Refs.SignatureScheme.EcdsaRfc6979Sha256, Sign = ByteString.CopyFrom(Key.SignData(response.MetaHeader.ToByteArray())) }, BodySignature = new Refs.Signature { Key = ByteString.CopyFrom(Key.PublicKey()), Scheme = Refs.SignatureScheme.EcdsaRfc6979Sha256, Sign = ByteString.CopyFrom(Key.SignData(response.GetBody().ToByteArray())) }, OriginSignature = new Refs.Signature { Key = ByteString.CopyFrom(Key.PublicKey()), Scheme = Refs.SignatureScheme.EcdsaRfc6979Sha256, Sign = ByteString.CopyFrom(Key.SignData([])) } }; return verifyHeader; } public ResponseMetaHeader ResponseMetaHeader => new() { Version = Version.ToMessage(), Epoch = 100, Ttl = 1 }; } public abstract class ContainerServiceBase(string key) : ServiceBase(key) { public Guid ContainerGuid { get; set; } = Guid.NewGuid(); public abstract Mock GetMock(); } public abstract class ObjectServiceBase(string key) : ServiceBase(key) { public abstract Mock GetMock(); public Guid ContainerGuid { get; set; } = Guid.NewGuid(); }