Added string utils
parent
57b5effaf2
commit
3f93b25ac2
@ -1,3 +1,22 @@
|
||||
export function test() {
|
||||
import ByteBuffer from 'bytebuffer';
|
||||
|
||||
type Encoding = 'base64' | 'hex' | 'binary' | 'utf8';
|
||||
type BufferType = ByteBuffer | Buffer | ArrayBuffer | Uint8Array;
|
||||
|
||||
/**
|
||||
* Take a string value with the given encoding and converts it to an `ArrayBuffer`.
|
||||
* @param value The string value.
|
||||
* @param encoding The encoding of the string value.
|
||||
*/
|
||||
export function encode(value: string, encoding: Encoding): ArrayBuffer {
|
||||
return ByteBuffer.wrap(value, encoding).toArrayBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a buffer and convert it to a string with the given encoding.
|
||||
* @param buffer The buffer.
|
||||
* @param stringEncoding The encoding of the converted string value.
|
||||
*/
|
||||
export function decode(buffer: BufferType, stringEncoding: Encoding): string {
|
||||
return ByteBuffer.wrap(buffer).toString(stringEncoding);
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
import { CipherTextObject } from '../../../../../libtextsecure/libsignal-protocol';
|
||||
import { SignalService } from '../../../../protobuf';
|
||||
import { StringUtils } from '../../../../session/utils';
|
||||
|
||||
export class FallBackSessionCipherStub {
|
||||
public async encrypt(buffer: ArrayBuffer): Promise<CipherTextObject> {
|
||||
return {
|
||||
type: SignalService.Envelope.Type.SESSION_REQUEST,
|
||||
body: Buffer.from(buffer).toString('binary'),
|
||||
body: StringUtils.decode(buffer, 'binary'),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue