How to use writeBuffer method in Best

Best JavaScript code snippet using best

pkcs8.js

Source:pkcs8.js Github

copy

Full Screen

...346 der.startSequence();347 if (PrivateKey.isPrivateKey(key)) {348 var sillyInt = new Buffer(1);349 sillyInt[0] = 0x0;350 der.writeBuffer(sillyInt, asn1.Ber.Integer);351 }352 der.startSequence();353 switch (key.type) {354 case 'rsa':355 der.writeOID('1.2.840.113549.1.1.1');356 if (PrivateKey.isPrivateKey(key))357 writePkcs8RSAPrivate(key, der);358 else359 writePkcs8RSAPublic(key, der);360 break;361 case 'dsa':362 der.writeOID('1.2.840.10040.4.1');363 if (PrivateKey.isPrivateKey(key))364 writePkcs8DSAPrivate(key, der);365 else366 writePkcs8DSAPublic(key, der);367 break;368 case 'ecdsa':369 der.writeOID('1.2.840.10045.2.1');370 if (PrivateKey.isPrivateKey(key))371 writePkcs8ECDSAPrivate(key, der);372 else373 writePkcs8ECDSAPublic(key, der);374 break;375 case 'ed25519':376 der.writeOID('1.3.101.112');377 if (PrivateKey.isPrivateKey(key))378 throw (new Error('Ed25519 private keys in pkcs8 ' +379 'format are not supported'));380 writePkcs8EdDSAPublic(key, der);381 break;382 default:383 throw (new Error('Unsupported key type: ' + key.type));384 }385 der.endSequence();386}387function writePkcs8RSAPrivate(key, der) {388 der.writeNull();389 der.endSequence();390 der.startSequence(asn1.Ber.OctetString);391 der.startSequence();392 var version = new Buffer(1);393 version[0] = 0;394 der.writeBuffer(version, asn1.Ber.Integer);395 der.writeBuffer(key.part.n.data, asn1.Ber.Integer);396 der.writeBuffer(key.part.e.data, asn1.Ber.Integer);397 der.writeBuffer(key.part.d.data, asn1.Ber.Integer);398 der.writeBuffer(key.part.p.data, asn1.Ber.Integer);399 der.writeBuffer(key.part.q.data, asn1.Ber.Integer);400 if (!key.part.dmodp || !key.part.dmodq)401 utils.addRSAMissing(key);402 der.writeBuffer(key.part.dmodp.data, asn1.Ber.Integer);403 der.writeBuffer(key.part.dmodq.data, asn1.Ber.Integer);404 der.writeBuffer(key.part.iqmp.data, asn1.Ber.Integer);405 der.endSequence();406 der.endSequence();407}408function writePkcs8RSAPublic(key, der) {409 der.writeNull();410 der.endSequence();411 der.startSequence(asn1.Ber.BitString);412 der.writeByte(0x00);413 der.startSequence();414 der.writeBuffer(key.part.n.data, asn1.Ber.Integer);415 der.writeBuffer(key.part.e.data, asn1.Ber.Integer);416 der.endSequence();417 der.endSequence();418}419function writePkcs8DSAPrivate(key, der) {420 der.startSequence();421 der.writeBuffer(key.part.p.data, asn1.Ber.Integer);422 der.writeBuffer(key.part.q.data, asn1.Ber.Integer);423 der.writeBuffer(key.part.g.data, asn1.Ber.Integer);424 der.endSequence();425 der.endSequence();426 der.startSequence(asn1.Ber.OctetString);427 der.writeBuffer(key.part.x.data, asn1.Ber.Integer);428 der.endSequence();429}430function writePkcs8DSAPublic(key, der) {431 der.startSequence();432 der.writeBuffer(key.part.p.data, asn1.Ber.Integer);433 der.writeBuffer(key.part.q.data, asn1.Ber.Integer);434 der.writeBuffer(key.part.g.data, asn1.Ber.Integer);435 der.endSequence();436 der.endSequence();437 der.startSequence(asn1.Ber.BitString);438 der.writeByte(0x00);439 der.writeBuffer(key.part.y.data, asn1.Ber.Integer);440 der.endSequence();441}442function writeECDSACurve(key, der) {443 var curve = algs.curves[key.curve];444 if (curve.pkcs8oid) {445 /* This one has a name in pkcs#8, so just write the oid */446 der.writeOID(curve.pkcs8oid);447 } else {448 // ECParameters sequence449 der.startSequence();450 var version = new Buffer(1);451 version.writeUInt8(1, 0);452 der.writeBuffer(version, asn1.Ber.Integer);453 // FieldID sequence454 der.startSequence();455 der.writeOID('1.2.840.10045.1.1'); // prime-field456 der.writeBuffer(curve.p, asn1.Ber.Integer);457 der.endSequence();458 // Curve sequence459 der.startSequence();460 var a = curve.p;461 if (a[0] === 0x0)462 a = a.slice(1);463 der.writeBuffer(a, asn1.Ber.OctetString);464 der.writeBuffer(curve.b, asn1.Ber.OctetString);465 der.writeBuffer(curve.s, asn1.Ber.BitString);466 der.endSequence();467 der.writeBuffer(curve.G, asn1.Ber.OctetString);468 der.writeBuffer(curve.n, asn1.Ber.Integer);469 var h = curve.h;470 if (!h) {471 h = new Buffer(1);472 h[0] = 1;473 }474 der.writeBuffer(h, asn1.Ber.Integer);475 // ECParameters476 der.endSequence();477 }478}479function writePkcs8ECDSAPublic(key, der) {480 writeECDSACurve(key, der);481 der.endSequence();482 var Q = utils.ecNormalize(key.part.Q.data, true);483 der.writeBuffer(Q, asn1.Ber.BitString);484}485function writePkcs8ECDSAPrivate(key, der) {486 writeECDSACurve(key, der);487 der.endSequence();488 der.startSequence(asn1.Ber.OctetString);489 der.startSequence();490 var version = new Buffer(1);491 version[0] = 1;492 der.writeBuffer(version, asn1.Ber.Integer);493 der.writeBuffer(key.part.d.data, asn1.Ber.OctetString);494 der.startSequence(0xa1);495 var Q = utils.ecNormalize(key.part.Q.data, true);496 der.writeBuffer(Q, asn1.Ber.BitString);497 der.endSequence();498 der.endSequence();499 der.endSequence();500}501function writePkcs8EdDSAPublic(key, der) {502 der.endSequence();503 utils.writeBitString(der, key.part.A.data);504}505function writePkcs8EdDSAPrivate(key, der) {506 der.endSequence();507 var k = utils.mpNormalize(key.part.k.data, true);508 der.startSequence(asn1.Ber.OctetString);509 der.writeBuffer(k, asn1.Ber.OctetString);510 der.endSequence();...

Full Screen

Full Screen

pkcs1.js

Source:pkcs1.js Github

copy

Full Screen

...234 }235 der.endSequence();236}237function writePkcs1RSAPublic(der, key) {238 der.writeBuffer(key.part.n.data, asn1.Ber.Integer);239 der.writeBuffer(key.part.e.data, asn1.Ber.Integer);240}241function writePkcs1RSAPrivate(der, key) {242 var ver = new Buffer(1);243 ver[0] = 0;244 der.writeBuffer(ver, asn1.Ber.Integer);245 der.writeBuffer(key.part.n.data, asn1.Ber.Integer);246 der.writeBuffer(key.part.e.data, asn1.Ber.Integer);247 der.writeBuffer(key.part.d.data, asn1.Ber.Integer);248 der.writeBuffer(key.part.p.data, asn1.Ber.Integer);249 der.writeBuffer(key.part.q.data, asn1.Ber.Integer);250 if (!key.part.dmodp || !key.part.dmodq)251 utils.addRSAMissing(key);252 der.writeBuffer(key.part.dmodp.data, asn1.Ber.Integer);253 der.writeBuffer(key.part.dmodq.data, asn1.Ber.Integer);254 der.writeBuffer(key.part.iqmp.data, asn1.Ber.Integer);255}256function writePkcs1DSAPrivate(der, key) {257 var ver = new Buffer(1);258 ver[0] = 0;259 der.writeBuffer(ver, asn1.Ber.Integer);260 der.writeBuffer(key.part.p.data, asn1.Ber.Integer);261 der.writeBuffer(key.part.q.data, asn1.Ber.Integer);262 der.writeBuffer(key.part.g.data, asn1.Ber.Integer);263 der.writeBuffer(key.part.y.data, asn1.Ber.Integer);264 der.writeBuffer(key.part.x.data, asn1.Ber.Integer);265}266function writePkcs1DSAPublic(der, key) {267 der.writeBuffer(key.part.y.data, asn1.Ber.Integer);268 der.writeBuffer(key.part.p.data, asn1.Ber.Integer);269 der.writeBuffer(key.part.q.data, asn1.Ber.Integer);270 der.writeBuffer(key.part.g.data, asn1.Ber.Integer);271}272function writePkcs1ECDSAPublic(der, key) {273 der.startSequence();274 der.writeOID('1.2.840.10045.2.1'); /* ecPublicKey */275 var curve = key.part.curve.data.toString();276 var curveOid = algs.curves[curve].pkcs8oid;277 assert.string(curveOid, 'a known ECDSA named curve');278 der.writeOID(curveOid);279 der.endSequence();280 var Q = utils.ecNormalize(key.part.Q.data, true);281 der.writeBuffer(Q, asn1.Ber.BitString);282}283function writePkcs1ECDSAPrivate(der, key) {284 var ver = new Buffer(1);285 ver[0] = 1;286 der.writeBuffer(ver, asn1.Ber.Integer);287 der.writeBuffer(key.part.d.data, asn1.Ber.OctetString);288 der.startSequence(0xa0);289 var curve = key.part.curve.data.toString();290 var curveOid = algs.curves[curve].pkcs8oid;291 assert.string(curveOid, 'a known ECDSA named curve');292 der.writeOID(curveOid);293 der.endSequence();294 der.startSequence(0xa1);295 var Q = utils.ecNormalize(key.part.Q.data, true);296 der.writeBuffer(Q, asn1.Ber.BitString);297 der.endSequence();298}299function writePkcs1EdDSAPrivate(der, key) {300 var ver = new Buffer(1);301 ver[0] = 1;302 der.writeBuffer(ver, asn1.Ber.Integer);303 der.writeBuffer(key.part.k.data, asn1.Ber.OctetString);304 der.startSequence(0xa0);305 der.writeOID('1.3.101.112');306 der.endSequence();307 der.startSequence(0xa1);308 utils.writeBitString(der, key.part.A.data);309 der.endSequence();310}311function writePkcs1EdDSAPublic(der, key) {312 throw (new Error('Public keys are not supported for EdDSA PKCS#1'));...

Full Screen

Full Screen

writeBuffer.spec.ts

Source:writeBuffer.spec.ts Github

copy

Full Screen

...17export const g = makeTestGroup(ValidationTest);18g.test('ranges')19 .desc(20 `21Tests that the data ranges given to GPUQueue.writeBuffer() are properly validated. Tests calling22writeBuffer with both TypedArrays and ArrayBuffers and checks that the data offset and size is23interpreted correctly for both.24 - When passing a TypedArray the data offset and size is given in elements.25 - When passing an ArrayBuffer the data offset and size is given in bytes.26Also verifies that the specified data range:27 - Describes a valid range of the source buffer.28 - Fits fully within the destination buffer.29 - Has a byte size which is a multiple of 4.30`31 )32 .fn(async t => {33 const queue = t.device.queue;34 function runTest(arrayType: TypedArrayBufferViewConstructor, testBuffer: boolean) {35 const elementSize = arrayType.BYTES_PER_ELEMENT;36 const bufferSize = 16 * elementSize;37 const buffer = t.device.createBuffer({38 size: bufferSize,39 usage: GPUBufferUsage.COPY_DST,40 });41 const arraySm: TypedArrayBufferView | ArrayBuffer = testBuffer42 ? new arrayType(8).buffer43 : new arrayType(8);44 const arrayMd: TypedArrayBufferView | ArrayBuffer = testBuffer45 ? new arrayType(16).buffer46 : new arrayType(16);47 const arrayLg: TypedArrayBufferView | ArrayBuffer = testBuffer48 ? new arrayType(32).buffer49 : new arrayType(32);50 if (elementSize < 4) {51 const array15: TypedArrayBufferView | ArrayBuffer = testBuffer52 ? new arrayType(15).buffer53 : new arrayType(15);54 // Writing the full buffer that isn't 4-byte aligned.55 t.shouldThrow('OperationError', () => queue.writeBuffer(buffer, 0, array15));56 // Writing from an offset that causes source to be 4-byte aligned.57 queue.writeBuffer(buffer, 0, array15, 3);58 // Writing from an offset that causes the source to not be 4-byte aligned.59 t.shouldThrow('OperationError', () => queue.writeBuffer(buffer, 0, arrayMd, 3));60 // Writing with a size that is not 4-byte aligned.61 t.shouldThrow('OperationError', () => queue.writeBuffer(buffer, 0, arraySm, 0, 7));62 }63 // Writing the full buffer without offsets.64 queue.writeBuffer(buffer, 0, arraySm);65 queue.writeBuffer(buffer, 0, arrayMd);66 t.expectValidationError(() => queue.writeBuffer(buffer, 0, arrayLg));67 // Writing the full buffer with a 4-byte aligned offset.68 queue.writeBuffer(buffer, 8, arraySm);69 t.expectValidationError(() => queue.writeBuffer(buffer, 8, arrayMd));70 // Writing the full buffer with a unaligned offset.71 t.shouldThrow('OperationError', () => queue.writeBuffer(buffer, 3, arraySm));72 // Writing remainder of buffer from offset.73 queue.writeBuffer(buffer, 0, arraySm, 4);74 queue.writeBuffer(buffer, 0, arrayMd, 4);75 t.expectValidationError(() => queue.writeBuffer(buffer, 0, arrayLg, 4));76 // Writing a larger buffer from an offset that allows it to fit in the destination.77 queue.writeBuffer(buffer, 0, arrayLg, 16);78 // Writing with both an offset and size.79 queue.writeBuffer(buffer, 0, arraySm, 4, 4);80 // Writing with a size that extends past the source buffer length.81 t.shouldThrow('OperationError', () => queue.writeBuffer(buffer, 0, arraySm, 0, 16));82 t.shouldThrow('OperationError', () => queue.writeBuffer(buffer, 0, arraySm, 4, 8));83 // Writing with a size that is 4-byte aligned but an offset that is not.84 queue.writeBuffer(buffer, 0, arraySm, 3, 4);85 // Writing zero bytes at the end of the buffer86 queue.writeBuffer(buffer, bufferSize, arraySm, 0, 0);87 // Writing zero bytes from the end of the data88 queue.writeBuffer(buffer, 0, arraySm, 8, 0);89 // A data offset of undefined should be treated as 090 queue.writeBuffer(buffer, 0, arraySm, undefined, 8);91 t.shouldThrow('OperationError', () => queue.writeBuffer(buffer, 0, arraySm, undefined, 12));92 }93 const arrayTypes = [94 Uint8Array,95 Uint8Array,96 Int8Array,97 Uint16Array,98 Int16Array,99 Uint32Array,100 Int32Array,101 Float32Array,102 Float64Array,103 ];104 runTest(Uint8Array, true);105 for (const arrayType of arrayTypes) {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var http = require('http');2var fs = require('fs');3var path = require('path');4var url = require('url');5var http = require('http');6var https = require('https');7var zlib = require('zlib');8var crypto = require('crypto');9var stream = require('stream');10var util = require('util');11var os = require('os');12var EventEmitter = require('events').EventEmitter;13var Readable = stream.Readable;14var Writable = stream.Writable;15var Transform = stream.Transform;16var Duplex = stream.Duplex;17var PassThrough = stream.PassThrough;18var Buffer = require('buffer').Buffer;19var URL = require('url');20var querystring = require('querystring');21var Cookie = require('cookie');22var FormData = require('form-data');23var net = require('net');24var tls = require('tls');25var httpAgent = require('agentkeepalive');26var httpsAgent = require('agentkeepalive').HttpsAgent;27var extend = require('extend');28var mime = require('mime');29var mimeTypes = require('mime-types');30var mimeDb = require('mime-db');31var mimeExtensions = require('mime-db').extensions;32var mimeTypesExtensions = require('mime-types').extensions;33var mimeTypesLookup = require('mime-types').lookup;34var mimeTypesContentType = require('mime-types').contentType;35var mimeTypesExtension = require('mime-types').extension;36var mimeTypesCharset = require('mime-types').charset;37var httpProxy = require('http-proxy');38var httpProxyAgent = require('http-proxy-agent');39var httpsProxyAgent = require('https-proxy-agent');40var httpSignature = require('http-signature');41var httpDigest = require('http-digest-client');42var WebSocket = require('ws');43var WebSocketServer = require('ws').Server;44var WebSocketClient = require('ws').WebSocket;45var WebSocketStream = require('websocket-stream');46var WebSocketStreamServer = require('websocket-stream').Server;47var WebSocketStreamClient = require('websocket-stream').WebSocket;48var WebSocketStreamDuplex = require('websocket-stream').Duplex;49var WebSocketStreamTransform = require('websocket-stream').Transform;50var WebSocketStreamPassThrough = require('websocket-stream').PassThrough;51var WebSocketStreamReadable = require('websocket-stream').Readable;52var WebSocketStreamWritable = require('websocket-stream').Writable;53var WebSocketStreamString = require('websocket-stream').String;

Full Screen

Using AI Code Generation

copy

Full Screen

1socket.OnConnected += OnConnected;2socket.OnClosed += OnClosed;3socket.OnPacket += OnPacket;4socket.Open();5function OnConnected(socket: BestHTTP.SocketIO.Socket) {6 Debug.Log("Connected to server!");7}8function OnClosed(socket: BestHTTP.SocketIO.Socket, wasClean: boolean) {9 Debug.Log("Connection closed!");10}11function OnPacket(socket: BestHTTP.SocketIO.Socket, packet: BestHTTP.SocketIO.Events.SocketPacket) {12 Debug.Log("Packet received: " + packet.ToString());13}14function SendBuffer() {15 var buffer: byte[] = new byte[10];16 buffer[0] = 1;17 buffer[1] = 2;18 buffer[2] = 3;19 buffer[3] = 4;20 buffer[4] = 5;21 buffer[5] = 6;22 buffer[6] = 7;23 buffer[7] = 8;24 buffer[8] = 9;25 buffer[9] = 10;26 socket.WriteBuffer(buffer);27}28socket.OnConnected += OnConnected;29socket.OnClosed += OnClosed;30socket.OnPacket += OnPacket;31socket.Open();32function OnConnected(socket: BestHTTP.SocketIO.Socket) {33 Debug.Log("Connected to server!");34}35function OnClosed(socket: BestHTTP.SocketIO.Socket, wasClean: boolean) {36 Debug.Log("Connection closed!");37}38function OnPacket(socket: BestHTTP.SocketIO.Socket, packet: BestHTTP.SocketIO.Events.SocketPacket) {39 Debug.Log("Packet received: " + packet.ToString());40}41function SendBuffer() {42 var buffer: byte[] = new byte[10];43 buffer[0] = 1;44 buffer[1] = 2;45 buffer[2] = 3;46 buffer[3] = 4;47 buffer[4] = 5;48 buffer[5] = 6;

Full Screen

Using AI Code Generation

copy

Full Screen

1socket.On("open", (s, p) => {2 Debug.Log("Connection Open");3 byte[] buffer = new byte[4];4 buffer[0] = 0;5 buffer[1] = 1;6 buffer[2] = 2;7 buffer[3] = 3;8 socket.WriteBuffer(buffer);9});10socket.On("error", (s, p) => {11 Debug.Log("Error: " + p.ToString());12});13socket.On("close", (s, p) => {14 Debug.Log("Connection Closed");15});16socket.On("message", (s, p) => {17 Debug.Log("Message: " + p.ToString());18});19socket.On("binary", (s, p) => {20 Debug.Log("Binary: " + p.ToString());21});22socket.Connect();23socket.On("open", (s, p) => {24 Debug.Log("Connection Open");25 byte[] buffer = new byte[4];26 buffer[0] = 0;27 buffer[1] = 1;28 buffer[2] = 2;29 buffer[3] = 3;30 socket.WriteBuffer(buffer);31});32socket.On("error", (s, p) => {33 Debug.Log("Error: " + p.ToString());34});35socket.On("close", (s, p) => {36 Debug.Log("Connection Closed");37});38socket.On("message", (s, p) => {39 Debug.Log("Message: " + p.ToString());40});41socket.On("binary", (s, p) => {42 Debug.Log("Binary: " + p.ToString());43});44socket.Connect();45socket.On("open", (s, p) => {46 Debug.Log("Connection Open");47 byte[] buffer = new byte[4];48 buffer[0] = 0;49 buffer[1] = 1;50 buffer[2] = 2;

Full Screen

Using AI Code Generation

copy

Full Screen

1var request = new BestHTTP.HTTPRequest();2request.MethodType = BestHTTP.HTTPMethods.Get;3request.Timeout = new TimeSpan(0, 0, 10);4request.Callback = OnReadComplete;5request.Send();6var request2 = new BestHTTP.HTTPRequest();7request2.MethodType = BestHTTP.HTTPMethods.Put;8request2.Timeout = new TimeSpan(0, 0, 10);9request2.Callback = OnWriteComplete;10request2.Send();

Full Screen

Using AI Code Generation

copy

Full Screen

1var http = require('best-http');2var fs = require('fs');3var data = "This data is written into the file using writeBuffer method";4var buffer = new Buffer(data, 'utf-8');5var options = {6};7var req = http.request(options, function (res) {8 var file = fs.createWriteStream("image.png");9 res.on('data', function (chunk) {10 file.write(chunk);11 });12 res.on('end', function () {13 console.log('file downloaded');14 file.end();15 });16});17req.end();18req.on('error', function (e) {19 console.log('problem with request: ' + e.message);20});21var http = require('best-http');22var fs = require('fs');23var data = "This data is written into the file using writeBuffer method";24var buffer = new Buffer(data, 'utf-8');25var options = {26};27var req = http.request(options, function (res) {28 var file = fs.createWriteStream("image.png");29 res.on('data', function (chunk) {30 file.write(chunk);31 });32 res.on('end', function () {33 console.log('file downloaded');34 file.end();35 });36});37req.end();38req.on('error', function (e) {39 console.log('problem with request: ' + e.message);40});41var http = require('best-http');42var fs = require('fs');43var data = "This data is written into the file using writeBuffer method";44var buffer = new Buffer(data, 'utf-8');45var options = {46};47var req = http.request(options, function (res) {48 var file = fs.createWriteStream("image.png");

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Best automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful