// Path: src/main/java/com/yammer/httptunnel/client/ProxyAuthenticationException.java
// public class ProxyAuthenticationException extends Exception {
// 
// 	private static final long serialVersionUID = 997754190727366945L;
// 
// 	public ProxyAuthenticationException(String message) {
// 		super(message);
// 	}
// }
// 
// Path: src/main/java/com/yammer/httptunnel/util/StringUtils.java
// public class StringUtils {
// 
// 	private StringUtils() { }
// 
// 	public static String capitalize(String str) {
// 		if (str.isEmpty())
// 			return str;
// 
// 		return str.substring(0, 1).toUpperCase() + str.substring(1).toLowerCase();
// 	}
// 
// 	public static String leftPad(String str, int length, char padding) {
// 		final int paddingLength = length - str.length();
// 		if (paddingLength < 0)
// 			return str;
// 
// 		final StringBuilder builder = new StringBuilder(length);
// 
// 		while (builder.length() < paddingLength)
// 			builder.append(padding);
// 
// 		builder.append(str);
// 
// 		return builder.toString();
// 	}
// 
// 	public static boolean inCharArray(char[] haystack, char needle) {
// 		for (char candidate : haystack) {
// 			if (candidate == needle)
// 				return true;
// 		}
// 
// 		return false;
// 	}
// 
// 	public static boolean inStringArray(String[] haystack, String needle) {
// 		for (String candidate : haystack) {
// 			if (candidate == null) {
// 				if (needle == null)
// 					return true;
// 
// 				continue;
// 			}
// 
// 			if (candidate.equals(needle))
// 				return true;
// 		}
// 
// 		return false;
// 	}
// 
// 	public static String bytesToHex(byte[] bytes) {
// 		final Formatter formatter = new Formatter();
// 
// 		for (byte b : bytes)
// 			formatter.format("%02x", b);
// 
// 		return formatter.toString();
// 	}
// }


import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.jboss.netty.handler.codec.http.HttpRequest;
import com.yammer.httptunnel.client.ProxyAuthenticationException;
import com.yammer.httptunnel.util.StringUtils;
/*
 * Copyright 2011 The Netty Project
 *
 * The Netty Project 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 com.yammer.httptunnel.client.auth;




/**
 * An implementation of HTTP digest authentication for use with proxy
 * authentication. See RFC 2617.
 *
 * @author The Netty Project (netty-dev@lists.jboss.org)
 * @author Iain McGinniss (iain.mcginniss@onedrum.com)
 * @author Jamie Furness (jamie@onedrum.com)
 * @author OneDrum Ltd.
 */
public class DigestAuthScheme implements AuthScheme {

	private static final String NAME = "digest";
	private static final String[] requiredParams = {"realm", "nonce", "qop"}; // Technically qop is optional, but *should* be implemented

	private static final Random random;

	static {
		random = new Random();
	}

	private static String generateNonce() {
		final byte[] bytes = new byte[8];

		random.nextBytes(bytes);

// Path: src/main/java/com/yammer/httptunnel/client/ProxyAuthenticationException.java
// public class ProxyAuthenticationException extends Exception {
// 
// 	private static final long serialVersionUID = 997754190727366945L;
// 
// 	public ProxyAuthenticationException(String message) {
// 		super(message);
// 	}
// }
// 
// Path: src/main/java/com/yammer/httptunnel/util/StringUtils.java
// public class StringUtils {
// 
// 	private StringUtils() { }
// 
// 	public static String capitalize(String str) {
// 		if (str.isEmpty())
// 			return str;
// 
// 		return str.substring(0, 1).toUpperCase() + str.substring(1).toLowerCase();
// 	}
// 
// 	public static String leftPad(String str, int length, char padding) {
// 		final int paddingLength = length - str.length();
// 		if (paddingLength < 0)
// 			return str;
// 
// 		final StringBuilder builder = new StringBuilder(length);
// 
// 		while (builder.length() < paddingLength)
// 			builder.append(padding);
// 
// 		builder.append(str);
// 
// 		return builder.toString();
// 	}
// 
// 	public static boolean inCharArray(char[] haystack, char needle) {
// 		for (char candidate : haystack) {
// 			if (candidate == needle)
// 				return true;
// 		}
// 
// 		return false;
// 	}
// 
// 	public static boolean inStringArray(String[] haystack, String needle) {
// 		for (String candidate : haystack) {
// 			if (candidate == null) {
// 				if (needle == null)
// 					return true;
// 
// 				continue;
// 			}
// 
// 			if (candidate.equals(needle))
// 				return true;
// 		}
// 
// 		return false;
// 	}
// 
// 	public static String bytesToHex(byte[] bytes) {
// 		final Formatter formatter = new Formatter();
// 
// 		for (byte b : bytes)
// 			formatter.format("%02x", b);
// 
// 		return formatter.toString();
// 	}
// }


// Path: src/main/java/com/yammer/httptunnel/client/auth/DigestAuthScheme.java
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.jboss.netty.handler.codec.http.HttpRequest;
import com.yammer.httptunnel.client.ProxyAuthenticationException;
import com.yammer.httptunnel.util.StringUtils;

/*
 * Copyright 2011 The Netty Project
 *
 * The Netty Project 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 com.yammer.httptunnel.client.auth;




/**
 * An implementation of HTTP digest authentication for use with proxy
 * authentication. See RFC 2617.
 *
 * @author The Netty Project (netty-dev@lists.jboss.org)
 * @author Iain McGinniss (iain.mcginniss@onedrum.com)
 * @author Jamie Furness (jamie@onedrum.com)
 * @author OneDrum Ltd.
 */
public class DigestAuthScheme implements AuthScheme {

	private static final String NAME = "digest";
	private static final String[] requiredParams = {"realm", "nonce", "qop"}; // Technically qop is optional, but *should* be implemented

	private static final Random random;

	static {
		random = new Random();
	}

	private static String generateNonce() {
		final byte[] bytes = new byte[8];

		random.nextBytes(bytes);

		return StringUtils.bytesToHex(bytes);