53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
export class CryptSettings
|
|
{
|
|
publicKey:Buffer;
|
|
iv:Buffer;
|
|
|
|
static from( serializedSettings:SerializedCryptSettings )
|
|
{
|
|
let settings = new CryptSettings();
|
|
|
|
settings.iv = Buffer.alloc( serializedSettings.iv.length );
|
|
settings.publicKey = Buffer.alloc( serializedSettings.publicKey.length );
|
|
|
|
|
|
for ( let i = 0; i < serializedSettings.publicKey.length; i++ )
|
|
{
|
|
settings.publicKey[ i ] = serializedSettings.publicKey[ i ]
|
|
}
|
|
|
|
for ( let i = 0; i < serializedSettings.iv.length; i++ )
|
|
{
|
|
settings.iv[ i ] = serializedSettings.iv[ i ]
|
|
}
|
|
|
|
return settings;
|
|
}
|
|
}
|
|
|
|
export class SerializedCryptSettings
|
|
{
|
|
publicKey:number[];
|
|
iv:number[];
|
|
|
|
static from( cryptSettings:CryptSettings )
|
|
{
|
|
let serialized = new SerializedCryptSettings();
|
|
serialized.iv = [];
|
|
serialized.publicKey = [];
|
|
|
|
for ( let i = 0; i < cryptSettings.publicKey.byteLength; i++ )
|
|
{
|
|
let value = cryptSettings.publicKey[ i ]
|
|
serialized.publicKey.push( value );
|
|
}
|
|
|
|
for ( let i = 0; i < cryptSettings.iv.byteLength; i++ )
|
|
{
|
|
let value = cryptSettings.iv[ i ]
|
|
serialized.iv.push( value );
|
|
}
|
|
|
|
return serialized;
|
|
}
|
|
} |