2020-09-10 05:08:12 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace RobloxFiles.BinaryFormat.Chunks
|
2020-07-13 01:19:30 +00:00
|
|
|
|
{
|
2023-11-29 03:07:30 +00:00
|
|
|
|
public enum RbxSignatureType
|
2020-07-13 01:19:30 +00:00
|
|
|
|
{
|
2023-11-29 03:07:30 +00:00
|
|
|
|
Ed25519
|
|
|
|
|
}
|
2020-07-13 01:19:30 +00:00
|
|
|
|
|
2023-11-29 03:07:30 +00:00
|
|
|
|
public struct RbxSignature
|
|
|
|
|
{
|
|
|
|
|
public RbxSignatureType SignatureType;
|
|
|
|
|
public long PublicKeyId;
|
|
|
|
|
public byte[] Value;
|
2020-07-13 01:19:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class SIGN : IBinaryFileChunk
|
|
|
|
|
{
|
2023-11-29 03:07:30 +00:00
|
|
|
|
public RbxSignature[] Signatures;
|
2020-07-13 01:19:30 +00:00
|
|
|
|
|
|
|
|
|
public void Load(BinaryRobloxFileReader reader)
|
|
|
|
|
{
|
|
|
|
|
int numSignatures = reader.ReadInt32();
|
2023-11-29 03:07:30 +00:00
|
|
|
|
Signatures = new RbxSignature[numSignatures];
|
2020-07-13 01:19:30 +00:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < numSignatures; i++)
|
|
|
|
|
{
|
2023-11-29 03:07:30 +00:00
|
|
|
|
var signature = new RbxSignature
|
2020-07-13 01:19:30 +00:00
|
|
|
|
{
|
2023-11-29 03:07:30 +00:00
|
|
|
|
SignatureType = (RbxSignatureType)reader.ReadInt32(),
|
|
|
|
|
PublicKeyId = reader.ReadInt64(),
|
2020-07-13 01:19:30 +00:00
|
|
|
|
};
|
|
|
|
|
|
2023-11-29 03:07:30 +00:00
|
|
|
|
var length = reader.ReadInt32();
|
|
|
|
|
signature.Value = reader.ReadBytes(length);
|
2020-07-13 01:19:30 +00:00
|
|
|
|
Signatures[i] = signature;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var file = reader.File;
|
|
|
|
|
file.SIGN = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Save(BinaryRobloxFileWriter writer)
|
|
|
|
|
{
|
|
|
|
|
writer.Write(Signatures.Length);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < Signatures.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
var signature = Signatures[i];
|
|
|
|
|
|
2023-11-29 03:07:30 +00:00
|
|
|
|
writer.Write((int)signature.SignatureType);
|
|
|
|
|
writer.Write(signature.PublicKeyId);
|
2020-07-13 01:19:30 +00:00
|
|
|
|
|
2023-11-29 03:07:30 +00:00
|
|
|
|
writer.Write(signature.Value.Length);
|
|
|
|
|
writer.Write(signature.Value);
|
2020-07-13 01:19:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-10 05:08:12 +00:00
|
|
|
|
|
|
|
|
|
public void WriteInfo(StringBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
int numSignatures = Signatures.Length;
|
|
|
|
|
builder.AppendLine($"NumSignatures: {numSignatures}");
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < numSignatures; i++)
|
|
|
|
|
{
|
|
|
|
|
var signature = Signatures[i];
|
|
|
|
|
builder.AppendLine($"## Signature {i}");
|
|
|
|
|
|
2023-11-29 03:07:30 +00:00
|
|
|
|
var version = Enum.GetName(typeof(RbxSignatureType), signature.SignatureType);
|
|
|
|
|
builder.AppendLine($"- SignatureType: {version}");
|
2020-09-10 05:08:12 +00:00
|
|
|
|
|
2023-11-29 03:07:30 +00:00
|
|
|
|
var publicKeyId = signature.PublicKeyId;
|
|
|
|
|
builder.AppendLine($"- PublicKeyId: {publicKeyId}");
|
2020-09-10 05:08:12 +00:00
|
|
|
|
|
2023-11-29 03:07:30 +00:00
|
|
|
|
var value = Convert.ToBase64String(signature.Value);
|
|
|
|
|
builder.AppendLine($"- Value: {value}");
|
2020-09-10 05:08:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-13 01:19:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|