fherbreteau commented on code in PR #404:
URL: https://github.com/apache/mina-sshd/pull/404#discussion_r1311683836


##########
sshd-contrib/src/main/java/org/apache/sshd/contrib/server/session/proxyprotocolv2/utils/ProxyUtils.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sshd.contrib.server.session.proxyprotocolv2.utils;
+
+import java.util.Arrays;
+
+import org.apache.sshd.common.util.buffer.Buffer;
+import org.apache.sshd.common.util.buffer.BufferUtils;
+
+
+/**
+ * Proxy Utilities class
+ *
+ * @author Oodrive - François HERBRETEAU (f.herbret...@oodrive.com)
+ */
+public final class ProxyUtils {
+
+    private ProxyUtils() {
+        // Utility Class
+    }
+
+    /**
+     * Read an unsigned short value in network order.
+     *
+     * @param  buffer the buffer to read
+     * @return        an unsigned short
+     */
+    public static int readUnsignedShort(Buffer buffer) {
+        // Read the expected bytes from the buffer
+        byte[] datas = new byte[2];
+        buffer.getRawBytes(datas);
+        // Extends the array with 2 more bytes
+        datas = Arrays.copyOf(datas, 4);
+        // Extract the value
+        int value = (int) (BufferUtils.getUInt(datas, 0, Integer.BYTES) >> 
Short.SIZE);
+        return value & 0xFFFF;

Review Comment:
   Thx for the info.
   
   I will add a `Buffer.getUShort()` to improve the code readability of my 
implementation.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org
For additional commands, e-mail: dev-h...@mina.apache.org

Reply via email to