@Test(expected = WsDigestException.class) public void testComputeHashMissingKey() throws Exception { String key1 = "67 89"; String key2 = "12 34"; ByteBuffer key3 = ByteBuffer.allocate(0); WsUtils.computeHash(key1, key2, key3); }
public static ByteBuffer computeHash(CharSequence key1, CharSequence key2, ByteBuffer key3) throws WsDigestException, NoSuchAlgorithmException { MessageDigest md5 = MessageDigest.getInstance("MD5"); ByteBuffer buf = ByteBuffer.allocate(DIGEST_LENGTH); buf.putInt(parseIntKey(key1)); buf.putInt(parseIntKey(key2)); if (key3.remaining() != 8) { throw new WsDigestException("WebSocket key3 must be exactly 8 bytes"); } buf.put(key3); buf.flip(); byte[] input = new byte[DIGEST_LENGTH]; buf.get(input, 0, DIGEST_LENGTH); byte[] digest = md5.digest(input); return ByteBuffer.wrap(digest); }
WsUtils { public static ByteBuffer computeHash(CharSequence key1, CharSequence key2, ByteBuffer key3) throws WsDigestException, NoSuchAlgorithmException { MessageDigest md5 = MessageDigest.getInstance("MD5"); ByteBuffer buf = ByteBuffer.allocate(DIGEST_LENGTH); buf.putInt(parseIntKey(key1)); buf.putInt(parseIntKey(key2)); if (key3.remaining() != 8) { throw new WsDigestException("WebSocket key3 must be exactly 8 bytes"); } buf.put(key3); buf.flip(); byte[] input = new byte[DIGEST_LENGTH]; buf.get(input, 0, DIGEST_LENGTH); byte[] digest = md5.digest(input); return ByteBuffer.wrap(digest); } }
WsUtils { public static ByteBuffer computeHash(CharSequence key1, CharSequence key2, ByteBuffer key3) throws WsDigestException, NoSuchAlgorithmException { MessageDigest md5 = MessageDigest.getInstance("MD5"); ByteBuffer buf = ByteBuffer.allocate(DIGEST_LENGTH); buf.putInt(parseIntKey(key1)); buf.putInt(parseIntKey(key2)); if (key3.remaining() != 8) { throw new WsDigestException("WebSocket key3 must be exactly 8 bytes"); } buf.put(key3); buf.flip(); byte[] input = new byte[DIGEST_LENGTH]; buf.get(input, 0, DIGEST_LENGTH); byte[] digest = md5.digest(input); return ByteBuffer.wrap(digest); } private  WsUtils(); }
WsUtils { public static ByteBuffer computeHash(CharSequence key1, CharSequence key2, ByteBuffer key3) throws WsDigestException, NoSuchAlgorithmException { MessageDigest md5 = MessageDigest.getInstance("MD5"); ByteBuffer buf = ByteBuffer.allocate(DIGEST_LENGTH); buf.putInt(parseIntKey(key1)); buf.putInt(parseIntKey(key2)); if (key3.remaining() != 8) { throw new WsDigestException("WebSocket key3 must be exactly 8 bytes"); } buf.put(key3); buf.flip(); byte[] input = new byte[DIGEST_LENGTH]; buf.get(input, 0, DIGEST_LENGTH); byte[] digest = md5.digest(input); return ByteBuffer.wrap(digest); } private  WsUtils(); static void addExtensionFilters(List<WebSocketExtension> extensions,
                                           ExtensionHelper helper,
                                           IoFilterChain filterChain,
                                           boolean hasCodec); static ByteBuffer computeHash(CharSequence key1, CharSequence key2, ByteBuffer key3); static String acceptHash(String key); static int calculateEncodedLengthSize(int lengthValue); static void encodeLength(ByteBuffer buf, int lengthValue); static void handleExtensionNegotiationException(HttpAcceptSession session, List<String> clientRequestedExtensions,
                                                            ProtocolException e, Logger logger); static WebSocketWireProtocol guessWireProtocolVersion(HttpRequestMessage httpRequest); static List<WebSocketExtension> negotiateExtensionsAndSetResponseHeader(
                                                        WebSocketExtensionFactory factory,
                                                        WsResourceAddress address,
                                                        List<String> requestedExtensions,
                                                        HttpAcceptSession session,
                                                        String extendionsHeaderName, ExtensionHelper extensionHelper); static String negotiateWebSocketProtocol(HttpAcceptSession session, String protocolHeaderName,
                                                    List<String> clientRequestedWsProtocols,
                                                    List<String> serverWsProtocols); static void removeExtensionFilters(List<WebSocketExtension> extensions, IoFilterChain filterChain); static String secWebSocketKey(); }
WsUtils { public static ByteBuffer computeHash(CharSequence key1, CharSequence key2, ByteBuffer key3) throws WsDigestException, NoSuchAlgorithmException { MessageDigest md5 = MessageDigest.getInstance("MD5"); ByteBuffer buf = ByteBuffer.allocate(DIGEST_LENGTH); buf.putInt(parseIntKey(key1)); buf.putInt(parseIntKey(key2)); if (key3.remaining() != 8) { throw new WsDigestException("WebSocket key3 must be exactly 8 bytes"); } buf.put(key3); buf.flip(); byte[] input = new byte[DIGEST_LENGTH]; buf.get(input, 0, DIGEST_LENGTH); byte[] digest = md5.digest(input); return ByteBuffer.wrap(digest); } private  WsUtils(); static void addExtensionFilters(List<WebSocketExtension> extensions,
                                           ExtensionHelper helper,
                                           IoFilterChain filterChain,
                                           boolean hasCodec); static ByteBuffer computeHash(CharSequence key1, CharSequence key2, ByteBuffer key3); static String acceptHash(String key); static int calculateEncodedLengthSize(int lengthValue); static void encodeLength(ByteBuffer buf, int lengthValue); static void handleExtensionNegotiationException(HttpAcceptSession session, List<String> clientRequestedExtensions,
                                                            ProtocolException e, Logger logger); static WebSocketWireProtocol guessWireProtocolVersion(HttpRequestMessage httpRequest); static List<WebSocketExtension> negotiateExtensionsAndSetResponseHeader(
                                                        WebSocketExtensionFactory factory,
                                                        WsResourceAddress address,
                                                        List<String> requestedExtensions,
                                                        HttpAcceptSession session,
                                                        String extendionsHeaderName, ExtensionHelper extensionHelper); static String negotiateWebSocketProtocol(HttpAcceptSession session, String protocolHeaderName,
                                                    List<String> clientRequestedWsProtocols,
                                                    List<String> serverWsProtocols); static void removeExtensionFilters(List<WebSocketExtension> extensions, IoFilterChain filterChain); static String secWebSocketKey(); static final String SEC_WEB_SOCKET_VERSION; static final String SEC_WEB_SOCKET_KEY; static final String SEC_WEB_SOCKET_KEY1; static final String SEC_WEB_SOCKET_KEY2; static final String HEADER_X_WEBSOCKET_EXTENSIONS; static final String HEADER_WEBSOCKET_EXTENSIONS; static final String HEADER_SEC_WEBSOCKET_EXTENSIONS; static final TypedAttributeKey<List<WebSocketExtension>> ACTIVE_EXTENSIONS_KEY; }