org.apache.sshd.common.util.buffer.Buffer类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(213)

本文整理了Java中org.apache.sshd.common.util.buffer.Buffer类的一些代码示例,展示了Buffer类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer类的具体详情如下:
包路径:org.apache.sshd.common.util.buffer.Buffer
类名称:Buffer

Buffer介绍

[英]Provides an abstract message buffer for encoding SSH messages
[中]提供用于编码SSH消息的抽象消息缓冲区

代码示例

代码示例来源:origin: org.apache.sshd/sshd-common

public byte[] getCompactData() {
  int l = available();
  if (l > 0) {
    byte[] b = new byte[l];
    System.arraycopy(array(), rpos(), b, 0, l);
    return b;
  } else {
    return GenericUtils.EMPTY_BYTE_ARRAY;
  }
}

代码示例来源:origin: org.apache.sshd/sshd-core

@Override
public IoWriteFuture sendDebugMessage(boolean display, Object msg, String lang) throws IOException {
  String text = Objects.toString(msg, "");
  lang = (lang == null) ? "" : lang;
  Buffer buffer = createBuffer(SshConstants.SSH_MSG_DEBUG,
      text.length() + lang.length() + Integer.SIZE /* a few extras */);
  buffer.putBoolean(display);
  buffer.putString(text);
  buffer.putString(lang);
  return writePacket(buffer);
}

代码示例来源:origin: org.apache.sshd/sshd-sftp

protected void doWrite(Buffer buffer, int id) throws IOException {
  String handle = buffer.getString();
  long offset = buffer.getLong();
  int length = buffer.getInt();
  try {
    doWrite(id, handle, offset, length, buffer.array(), buffer.rpos(), buffer.available());
  } catch (IOException | RuntimeException e) {
    sendStatus(prepareReply(buffer), id, e, SftpConstants.SSH_FXP_WRITE, handle, offset, length);
    return;
  }
  sendStatus(prepareReply(buffer), id, SftpConstants.SSH_FX_OK, "");
}

代码示例来源:origin: org.apache.sshd/sshd-core

protected Buffer prepare(Buffer buf) {
  int len = buf.available();
  int rpos = buf.rpos();
  int wpos = buf.wpos();
  buf.rpos(rpos - 4);
  buf.wpos(rpos - 4);
  buf.putInt(len);
  buf.wpos(wpos);
  return buf;
}

代码示例来源:origin: org.apache.sshd/sshd-sftp

public static void encode(Buffer buffer, SpaceAvailableExtensionInfo info) {
    buffer.putLong(info.bytesOnDevice);
    buffer.putLong(info.unusedBytesOnDevice);
    buffer.putLong(info.bytesAvailableToUser);
    buffer.putLong(info.unusedBytesAvailableToUser);
    buffer.putInt(info.bytesPerAllocationUnit & 0xFFFFFFFFL);
  }
}

代码示例来源:origin: org.apache.sshd/sshd-sftp

public static void decode(Buffer buffer, SpaceAvailableExtensionInfo info) {
  info.bytesOnDevice = buffer.getLong();
  info.unusedBytesOnDevice = buffer.getLong();
  info.bytesAvailableToUser = buffer.getLong();
  info.unusedBytesAvailableToUser = buffer.getLong();
  info.bytesPerAllocationUnit = buffer.getInt();
}

代码示例来源:origin: org.apache.sshd/sshd-core

Buffer bs = new ByteArrayBuffer(id.length + username.length() + service.length() + name.length()
  + algo.length() + ByteArrayBuffer.DEFAULT_SIZE + Long.SIZE, false);
bs.putBytes(id);
bs.putByte(SshConstants.SSH_MSG_USERAUTH_REQUEST);
bs.putString(username);
bs.putString(service);
bs.putString(name);
bs.putBoolean(true);
bs.putString(algo);
bs.putPublicKey(key);
byte[] contents = bs.getCompactData();
byte[] sig;
try {
bs.clear();
bs.putString(algo);
bs.putBytes(sig);
buffer.putBytes(bs.array(), bs.rpos(), bs.available());

代码示例来源:origin: org.apache.sshd/sshd-common

@Override
public void compress(Buffer buffer) throws IOException {
  compresser.setInput(buffer.array(), buffer.rpos(), buffer.available());
  buffer.wpos(buffer.rpos());
  for (int len = compresser.deflate(tmpbuf, 0, tmpbuf.length, Deflater.SYNC_FLUSH);
      len > 0;
      len = compresser.deflate(tmpbuf, 0, tmpbuf.length, Deflater.SYNC_FLUSH)) {
    buffer.putRawBytes(tmpbuf, 0, len);
  }
}

代码示例来源:origin: org.apache.sshd/sshd-core

e = buffer.getMPIntAsBytes();
dh.setF(e);
k = dh.getK();
buffer.putRawPublicKey(kp.getPublic());
byte[] k_s = buffer.getCompactData();
buffer.clear();
buffer.putBytes(v_c);
buffer.putBytes(v_s);
buffer.putBytes(i_c);
buffer.putBytes(i_s);
buffer.putBytes(k_s);
buffer.putMPInt(e);
buffer.putMPInt(f);
buffer.putMPInt(k);
hash.update(buffer.array(), 0, buffer.available());
h = hash.digest();
sig.update(h);
buffer.clear();
buffer.putString(algo);
byte[] sigBytes = sig.sign();
buffer.putBytes(sigBytes);
byte[] sigH = buffer.getCompactData();
if (log.isTraceEnabled()) {
  log.trace("next({})[{}][K_S]:  {}", this, session, BufferUtils.toHex(k_s));

代码示例来源:origin: org.apache.sshd/sshd-core

int p = buffer.wpos();
buffer.wpos(p + SshConstants.MSG_KEX_COOKIE_SIZE);
synchronized (random) {
  random.fill(buffer.array(), p, SshConstants.MSG_KEX_COOKIE_SIZE);
if (traceEnabled) {
  log.trace("sendKexInit({}) cookie={}",
       this, BufferUtils.toHex(buffer.array(), p, SshConstants.MSG_KEX_COOKIE_SIZE, ':'));
    log.trace("sendKexInit({})[{}] {}", this, paramType.getDescription(), s);
  buffer.putString(GenericUtils.trimToEmpty(s));
buffer.putBoolean(false);   // first kex packet follows
buffer.putInt(0);   // reserved (FFU)
byte[] data = buffer.getCompactData();
writePacket(buffer);
return data;

代码示例来源:origin: org.apache.sshd/sshd-core

@Override
public void messageReceived(IoSession session, Readable message) throws Exception {
  ChannelForwardedX11 channel = (ChannelForwardedX11) session.getAttribute(ChannelForwardedX11.class);
  Buffer buffer = new ByteArrayBuffer(message.available() + Long.SIZE, false);
  buffer.putBuffer(message);
  if (log.isTraceEnabled()) {
    log.trace("messageReceived({}) channel={}, len={}", session, channel, buffer.available());
  }
  OutputStream outputStream = channel.getInvertedIn();
  outputStream.write(buffer.array(), buffer.rpos(), buffer.available());
  outputStream.flush();
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit.ssh.apache

private void sendMic(ClientSession session, String service)
    throws IOException, GSSException {
  state = ProtocolState.MIC_SENT;
  // Produce MIC
  Buffer micBuffer = new ByteArrayBuffer();
  micBuffer.putBytes(session.getSessionId());
  micBuffer.putByte(SshConstants.SSH_MSG_USERAUTH_REQUEST);
  micBuffer.putString(session.getUsername());
  micBuffer.putString(service);
  micBuffer.putString(getName());
  byte[] micBytes = micBuffer.getCompactData();
  byte[] mic = context.getMIC(micBytes, 0, micBytes.length,
      new MessageProp(0, true));
  Buffer buffer = session
      .createBuffer(SshConstants.SSH_MSG_USERAUTH_GSSAPI_MIC);
  buffer.putBytes(mic);
  session.writePacket(buffer);
}

代码示例来源:origin: org.apache.sshd/sshd-core

protected void handleDisconnect(Buffer buffer) throws Exception  {
  int code = buffer.getInt();
  String message = buffer.getString();
  String languageTag;
  // SSHD-738: avoid spamming the log with uninteresting
  // messages caused by buggy OpenSSH < 5.5
  if (buffer.available() > 0) {
    languageTag = buffer.getString();
  } else {
    languageTag = "";
  }
  handleDisconnect(code, message, languageTag, buffer);
}

代码示例来源:origin: org.apache.sshd/sshd-sftp

public static List<AclEntry> readACLs(Buffer buffer, int version) {
  int aclSize = buffer.getInt();
  int startPos = buffer.rpos();
  Buffer aclBuffer = new ByteArrayBuffer(buffer.array(), startPos, aclSize, true);
  List<AclEntry> acl = decodeACLs(aclBuffer, version);
  buffer.rpos(startPos + aclSize);
  return acl;
}

代码示例来源:origin: org.apache.sshd/sshd-sftp

protected void sendHandle(Buffer buffer, int id, String handle) throws IOException {
  buffer.putByte((byte) SftpConstants.SSH_FXP_HANDLE);
  buffer.putInt(id);
  buffer.putString(handle);
  send(buffer);
}

代码示例来源:origin: org.apache.sshd/sshd-osgi

@Override
public Buffer prepareBuffer(byte cmd, Buffer buffer) {
  buffer = validateTargetBuffer(cmd & 0xFF, buffer);
  buffer.rpos(SshConstants.SSH_PACKET_HEADER_LEN);
  buffer.wpos(SshConstants.SSH_PACKET_HEADER_LEN);
  buffer.putByte(cmd);
  return buffer;
}

代码示例来源:origin: org.apache.sshd/sshd-common

public void putMPInt(byte[] foo) {
  if ((foo[0] & 0x80) != 0) {
    putInt(foo.length + 1 /* padding */);
    putByte((byte) 0);
  } else {
    putInt(foo.length);
  }
  putRawBytes(foo);
}

代码示例来源:origin: org.apache.sshd/sshd-core

protected Buffer createBuffer(byte cmd, int extraLen) {
  Buffer buffer = new ByteArrayBuffer((extraLen <= 0) ? ByteArrayBuffer.DEFAULT_SIZE : extraLen + Byte.SIZE, false);
  buffer.putInt(0);
  buffer.putByte(cmd);
  return buffer;
}

代码示例来源:origin: org.apache.sshd/sshd-sftp

protected void doSpaceAvailable(Buffer buffer, int id) throws IOException {
  String path = buffer.getString();
  SpaceAvailableExtensionInfo info;
  try {
    info = doSpaceAvailable(id, path);
  } catch (IOException | RuntimeException e) {
    sendStatus(prepareReply(buffer), id, e, SftpConstants.SSH_FXP_EXTENDED, SftpConstants.EXT_SPACE_AVAILABLE, path);
    return;
  }
  buffer = prepareReply(buffer);
  buffer.putByte((byte) SftpConstants.SSH_FXP_EXTENDED_REPLY);
  buffer.putInt(id);
  SpaceAvailableExtensionInfo.encode(buffer, info);
  send(buffer);
}

代码示例来源:origin: org.apache.sshd/sshd-sftp

public static NavigableMap<String, byte[]> readExtensions(Buffer buffer) {
  int count = buffer.getInt();
  // NOTE
  NavigableMap<String, byte[]> extended = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
  for (int i = 0; i < count; i++) {
    String key = buffer.getString();
    byte[] val = buffer.getBytes();
    byte[] prev = extended.put(key, val);
    ValidateUtils.checkTrue(prev == null, "Duplicate values for extended key=%s", key);
  }
  return extended;
}

相关文章