(data, encoding, cb)
| 537 | _read(n) {} |
| 538 | |
| 539 | _write(data, encoding, cb) { |
| 540 | /* |
| 541 | Messages are of the format: |
| 542 | uint32 message length |
| 543 | byte message type |
| 544 | byte[message length - 1] message contents |
| 545 | */ |
| 546 | if (this[SYM_BUFFER] === null) |
| 547 | this[SYM_BUFFER] = data; |
| 548 | else |
| 549 | this[SYM_BUFFER] = concat(this[SYM_BUFFER], data); |
| 550 | |
| 551 | let buffer = this[SYM_BUFFER]; |
| 552 | let bufferLen = buffer.length; |
| 553 | |
| 554 | let p = 0; |
| 555 | while (p < bufferLen) { |
| 556 | // Wait for length + type |
| 557 | if (bufferLen < 5) |
| 558 | break; |
| 559 | |
| 560 | if (this[SYM_MSGLEN] === -1) |
| 561 | this[SYM_MSGLEN] = readUInt32BE(buffer, p); |
| 562 | |
| 563 | // Check if we have the entire message |
| 564 | if (bufferLen < (4 + this[SYM_MSGLEN])) |
| 565 | break; |
| 566 | |
| 567 | const msgType = buffer[p += 4]; |
| 568 | ++p; |
| 569 | |
| 570 | if (this[SYM_MODE] === ROLE_CLIENT) { |
| 571 | if (this[SYM_REQS].length === 0) |
| 572 | return cb(new Error('Received unexpected message from server')); |
| 573 | |
| 574 | const req = this[SYM_REQS].shift(); |
| 575 | |
| 576 | switch (msgType) { |
| 577 | case SSH_AGENT_FAILURE: |
| 578 | req.cb(new Error('Agent responded with failure')); |
| 579 | break; |
| 580 | case SSH_AGENT_IDENTITIES_ANSWER: { |
| 581 | if (req.type !== SSH_AGENTC_REQUEST_IDENTITIES) |
| 582 | return cb(new Error('Agent responded with wrong message type')); |
| 583 | |
| 584 | /* |
| 585 | byte SSH_AGENT_IDENTITIES_ANSWER |
| 586 | uint32 nkeys |
| 587 | |
| 588 | where `nkeys` is 0 or more of: |
| 589 | string key blob |
| 590 | string comment |
| 591 | */ |
| 592 | |
| 593 | binaryParser.init(buffer, p); |
| 594 | |
| 595 | const numKeys = binaryParser.readUInt32BE(); |
| 596 |
nothing calls this directly
no test coverage detected