本文整理了Java中org.apache.sshd.common.util.buffer.Buffer.getBytes()
方法的一些代码示例,展示了Buffer.getBytes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.getBytes()
方法的具体详情如下:
包路径:org.apache.sshd.common.util.buffer.Buffer
类名称:Buffer
方法名:getBytes
暂无
代码示例来源:origin: org.apache.sshd/sshd-common
public byte[] getMPIntAsBytes() {
return getBytes();
}
代码示例来源:origin: org.apache.sshd/sshd-osgi
public byte[] getMPIntAsBytes() {
return getBytes();
}
代码示例来源:origin: org.apache.sshd/sshd-core
@Override
public void handleIgnoreMessage(Session session, Buffer buffer) throws Exception {
handleIgnoreMessage(session, buffer.getBytes(), buffer);
}
代码示例来源:origin: org.apache.sshd/sshd-osgi
@Override
public void handleIgnoreMessage(Session session, Buffer buffer) throws Exception {
handleIgnoreMessage(session, buffer.getBytes(), 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;
}
代码示例来源:origin: org.apache.sshd/sshd-osgi
@Override
public PublicKey getRawPublicKey(String keyType, Buffer buffer) throws GeneralSecurityException {
ValidateUtils.checkTrue(isKeyTypeSupported(keyType), "Unsupported key type: %s", keyType);
byte[] seed = buffer.getBytes();
return SecurityUtils.generateEDDSAPublicKey(keyType, seed);
}
}
代码示例来源:origin: org.apache.sshd/sshd-common
@Override
public PublicKey getRawPublicKey(String keyType, Buffer buffer) throws GeneralSecurityException {
ValidateUtils.checkTrue(isKeyTypeSupported(keyType), "Unsupported key type: %s", keyType);
byte[] seed = buffer.getBytes();
return SecurityUtils.generateEDDSAPublicKey(keyType, seed);
}
}
代码示例来源:origin: org.apache.sshd/sshd-common
protected ECPublicKey getRawECKey(String expectedCurve, ECParameterSpec spec, Buffer buffer) throws GeneralSecurityException {
String curveName = buffer.getString();
if (!expectedCurve.equals(curveName)) {
throw new InvalidKeySpecException("getRawECKey(" + expectedCurve + ") curve name does not match expected: " + curveName);
}
if (spec == null) {
throw new InvalidKeySpecException("getRawECKey(" + expectedCurve + ") missing curve parameters");
}
byte[] octets = buffer.getBytes();
ECPoint w;
try {
w = ECCurves.octetStringToEcPoint(octets);
} catch (RuntimeException e) {
throw new InvalidKeySpecException("getRawECKey(" + expectedCurve + ")"
+ " cannot (" + e.getClass().getSimpleName() + ")"
+ " retrieve W value: " + e.getMessage(),
e);
}
return generatePublicKey(KeyUtils.EC_ALGORITHM, new ECPublicKeySpec(w, spec));
}
}
代码示例来源:origin: org.apache.sshd/sshd-osgi
protected KeyPair extractEC(String expectedCurveName, ECParameterSpec spec) throws GeneralSecurityException {
String curveName = getString();
if (!expectedCurveName.equals(curveName)) {
throw new InvalidKeySpecException("extractEC(" + expectedCurveName + ") mismatched curve name: " + curveName);
}
byte[] groupBytes = getBytes();
BigInteger exponent = getMPInt();
if (spec == null) {
throw new InvalidKeySpecException("extractEC(" + expectedCurveName + ") missing parameters for curve");
}
ECPoint group;
try {
group = ECCurves.octetStringToEcPoint(groupBytes);
} catch (RuntimeException e) {
throw new InvalidKeySpecException("extractEC(" + expectedCurveName + ")"
+ " failed (" + e.getClass().getSimpleName() + ")"
+ " to decode EC group for curve: " + e.getMessage(),
e);
}
KeyFactory keyFactory = SecurityUtils.getKeyFactory(KeyUtils.EC_ALGORITHM);
PublicKey pubKey = keyFactory.generatePublic(new ECPublicKeySpec(group, spec));
PrivateKey privKey = keyFactory.generatePrivate(new ECPrivateKeySpec(exponent, spec));
return new KeyPair(pubKey, privKey);
}
代码示例来源:origin: org.apache.sshd/sshd-common
protected KeyPair extractEC(String expectedCurveName, ECParameterSpec spec) throws GeneralSecurityException {
String curveName = getString();
if (!expectedCurveName.equals(curveName)) {
throw new InvalidKeySpecException("extractEC(" + expectedCurveName + ") mismatched curve name: " + curveName);
}
byte[] groupBytes = getBytes();
BigInteger exponent = getMPInt();
if (spec == null) {
throw new InvalidKeySpecException("extractEC(" + expectedCurveName + ") missing parameters for curve");
}
ECPoint group;
try {
group = ECCurves.octetStringToEcPoint(groupBytes);
} catch (RuntimeException e) {
throw new InvalidKeySpecException("extractEC(" + expectedCurveName + ")"
+ " failed (" + e.getClass().getSimpleName() + ")"
+ " to decode EC group for curve: " + e.getMessage(),
e);
}
KeyFactory keyFactory = SecurityUtils.getKeyFactory(KeyUtils.EC_ALGORITHM);
PublicKey pubKey = keyFactory.generatePublic(new ECPublicKeySpec(group, spec));
PrivateKey privKey = keyFactory.generatePrivate(new ECPrivateKeySpec(exponent, spec));
return new KeyPair(pubKey, privKey);
}
代码示例来源:origin: org.apache.sshd/sshd-osgi
protected ECPublicKey getRawECKey(String expectedCurve, ECParameterSpec spec, Buffer buffer) throws GeneralSecurityException {
String curveName = buffer.getString();
if (!expectedCurve.equals(curveName)) {
throw new InvalidKeySpecException("getRawECKey(" + expectedCurve + ") curve name does not match expected: " + curveName);
}
if (spec == null) {
throw new InvalidKeySpecException("getRawECKey(" + expectedCurve + ") missing curve parameters");
}
byte[] octets = buffer.getBytes();
ECPoint w;
try {
w = ECCurves.octetStringToEcPoint(octets);
} catch (RuntimeException e) {
throw new InvalidKeySpecException("getRawECKey(" + expectedCurve + ")"
+ " cannot (" + e.getClass().getSimpleName() + ")"
+ " retrieve W value: " + e.getMessage(),
e);
}
return generatePublicKey(KeyUtils.EC_ALGORITHM, new ECPublicKeySpec(w, spec));
}
}
代码示例来源:origin: org.apache.sshd/sshd-osgi
protected void messageReceived(Buffer buffer) throws Exception {
Buffer message = null;
synchronized (receiveBuffer) {
receiveBuffer.putBuffer(buffer);
if (receiveBuffer.available() >= 4) {
int rpos = receiveBuffer.rpos();
int len = receiveBuffer.getInt();
// Protect against malicious or corrupted packets
if (len < 0) {
throw new StreamCorruptedException("Illogical message length: " + len);
}
receiveBuffer.rpos(rpos);
if (receiveBuffer.available() >= (4 + len)) {
message = new ByteArrayBuffer(receiveBuffer.getBytes());
receiveBuffer.compact();
}
}
}
if (message != null) {
synchronized (messages) {
messages.offer(message);
messages.notifyAll();
}
}
}
代码示例来源:origin: org.apache.sshd/sshd-core
protected void messageReceived(Buffer buffer) throws Exception {
Buffer message = null;
synchronized (receiveBuffer) {
receiveBuffer.putBuffer(buffer);
if (receiveBuffer.available() >= 4) {
int rpos = receiveBuffer.rpos();
int len = receiveBuffer.getInt();
receiveBuffer.rpos(rpos);
if (receiveBuffer.available() >= 4 + len) {
message = new ByteArrayBuffer(receiveBuffer.getBytes());
receiveBuffer.compact();
}
}
}
if (message != null) {
synchronized (messages) {
messages.offer(message);
messages.notifyAll();
}
}
}
代码示例来源:origin: org.apache.sshd/sshd-sftp
Collection<byte[]> hashes = new LinkedList<>();
while (buffer.available() > 0) {
byte[] hashValue = buffer.getBytes();
hashes.add(hashValue);
代码示例来源:origin: org.apache.sshd/sshd-core
@Override
protected void doWriteData(byte[] data, int off, long len) throws IOException {
ValidateUtils.checkTrue(len <= Integer.MAX_VALUE, "Data length exceeds int boundaries: %d", len);
Buffer message = null;
synchronized (receiveBuffer) {
receiveBuffer.putBuffer(new ByteArrayBuffer(data, off, (int) len));
if (receiveBuffer.available() >= 4) {
off = receiveBuffer.rpos();
len = receiveBuffer.getInt();
receiveBuffer.rpos(off);
if (receiveBuffer.available() >= (4 + len)) {
message = new ByteArrayBuffer(receiveBuffer.getBytes());
receiveBuffer.compact();
}
}
}
if (message != null) {
synchronized (messages) {
messages.offer(message);
messages.notifyAll();
}
}
}
}
代码示例来源:origin: org.apache.sshd/sshd-sftp
byte[] hashValue = buffer.getBytes();
if (debugEnabled) {
log.debug("doGetHash({})[{}] - offset={}, length={}, quick-hash={} - result={}",
代码示例来源:origin: org.apache.sshd/sshd-sftp
@Override
protected void doInit(Buffer buffer, int id) throws IOException {
ServerSession session = getServerSession();
if (log.isDebugEnabled()) {
log.debug("doInit({})[id={}] SSH_FXP_INIT (version={})", session, id, id);
}
String all = checkVersionCompatibility(buffer, id, id, SftpConstants.SSH_FX_OP_UNSUPPORTED);
if (GenericUtils.isEmpty(all)) { // i.e. validation failed
return;
}
version = id;
while (buffer.available() > 0) {
String name = buffer.getString();
byte[] data = buffer.getBytes();
extensions.put(name, data);
}
buffer = prepareReply(buffer);
buffer.putByte((byte) SftpConstants.SSH_FXP_VERSION);
buffer.putInt(version);
appendExtensions(buffer, all);
SftpEventListener listener = getSftpEventListenerProxy();
listener.initialized(session, version);
send(buffer);
}
代码示例来源:origin: org.apache.sshd/sshd-osgi
@Override
protected void doWriteData(byte[] data, int off, long len) throws IOException {
ValidateUtils.checkTrue(len <= Integer.MAX_VALUE, "Data length exceeds int boundaries: %d", len);
Buffer message = null;
synchronized (receiveBuffer) {
receiveBuffer.putBuffer(new ByteArrayBuffer(data, off, (int) len));
if (receiveBuffer.available() >= 4) {
off = receiveBuffer.rpos();
len = receiveBuffer.getInt();
receiveBuffer.rpos(off);
if (receiveBuffer.available() >= (4 + len)) {
message = new ByteArrayBuffer(receiveBuffer.getBytes());
receiveBuffer.compact();
}
}
}
if (message != null) {
synchronized (messages) {
messages.offer(message);
messages.notifyAll();
}
}
}
}
代码示例来源:origin: org.apache.sshd/sshd-sftp
protected byte[] checkHandleResponse(int cmd, Buffer buffer) throws IOException {
int length = buffer.getInt();
int type = buffer.getUByte();
int id = buffer.getInt();
if (type == SftpConstants.SSH_FXP_HANDLE) {
return ValidateUtils.checkNotNullAndNotEmpty(buffer.getBytes(), "Null/empty handle in buffer", GenericUtils.EMPTY_OBJECT_ARRAY);
}
if (type == SftpConstants.SSH_FXP_STATUS) {
int substatus = buffer.getInt();
String msg = buffer.getString();
String lang = buffer.getString();
if (log.isTraceEnabled()) {
log.trace("checkHandleResponse({})[id={}] {} - status: {} [{}] {}",
getClientChannel(), id, SftpConstants.getCommandMessageName(cmd),
SftpConstants.getStatusName(substatus), lang, msg);
}
throwStatusException(cmd, id, substatus, msg, lang);
}
return handleUnexpectedHandlePacket(cmd, id, type, length, buffer);
}
代码示例来源:origin: org.apache.sshd/sshd-sftp
protected void doMD5Hash(Buffer buffer, int id, String targetType) throws IOException {
String target = buffer.getString();
long startOffset = buffer.getLong();
long length = buffer.getLong();
byte[] quickCheckHash = buffer.getBytes();
byte[] hashValue;
try {
hashValue = doMD5Hash(id, targetType, target, startOffset, length, quickCheckHash);
if (log.isTraceEnabled()) {
log.trace("doMD5Hash({})({})[{}] offset={}, length={}, quick-hash={} - hash={}",
getServerSession(), targetType, target, startOffset, length,
BufferUtils.toHex(':', quickCheckHash),
BufferUtils.toHex(':', hashValue));
}
} catch (Exception e) {
sendStatus(prepareReply(buffer), id, e,
SftpConstants.SSH_FXP_EXTENDED, targetType, target, startOffset, length, quickCheckHash);
return;
}
buffer = prepareReply(buffer);
buffer.putByte((byte) SftpConstants.SSH_FXP_EXTENDED_REPLY);
buffer.putInt(id);
buffer.putString(targetType);
buffer.putBytes(hashValue);
send(buffer);
}
内容来源于网络,如有侵权,请联系作者删除!