/*
 * 
 * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
 * 
 * The contents of this file are subject to the Sun Community Source
 * License v3.0/Jini Technology Specific Attachment v 1.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://wwws.sun.com/software/jini/licensing/SCSL3_JiniTSA1.html.
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 * the License for the specific language governing rights and limitations
 * under the License.
 * 
 * The Reference Code is Jini Technology Core Platform code, v2.0. The
 * Developer of the Reference Code is Sun Microsystems, Inc.
 * 
 * Contributor(s): Sun Microsystems, Inc.
 * 
 * The contents of this file comply with the Jini Technology Core
 * Platform Compatibility Kit, v2.0A.
 * 
 * Tester(s): Sun Microsystems, Inc.
 * 
 * Test Platform(s):
 * Java 2 SDK, Standard Edition, Version 1.4.2_03 for Solaris(TM)SPARC/x86
 * Java 2 SDK, Standard Edition, Version 1.4.2_03 for Linux (Intel x86)
 * Java 2 SDK, Standard Edition, Version 1.4.2_03 for Windows (Intel Platform)
 * 
 */

package net.jini.jeri.ssl;

import net.jini.core.constraint.Confidentiality;
import net.jini.core.constraint.InvocationConstraint;
import java.io.Serializable;

/**
 * Represents a constraint that, if confidentiality of message contents is
 * ensured, the specified strength of confidentiality be used. <p>
 *
 * The use of an instance of this constraint does not directly imply a {@link
 * Confidentiality#YES} constraint; that must be specified separately to ensure
 * that confidentiality is actually ensured. <p>
 *
 * Serialization for this class is guaranteed to produce instances that are
 * comparable with <code>==</code>. <p>
 *
 * This constraint is supported by the endpoints defined in this package. <p>
 *
 * The {@link SslTrustVerifier} trust verifier may be used for establishing
 * trust in remote proxies that use instances of this class.
 *
 * @author Sun Microsystems, Inc.
 * @see SslEndpoint
 * @see SslServerEndpoint
 * @see HttpsEndpoint
 * @see HttpsServerEndpoint
 * @see SslTrustVerifier
 * @since 2.0
 */
public final class ConfidentialityStrength
    implements InvocationConstraint, Serializable
{
    /* -- Fields -- */

    private static final long serialVersionUID = -5413316999614306469L;

    /**
     * If confidentiality of message contents is ensured, then use strong
     * confidentiality for message contents. <p>
     *
     * For the endpoints in this package, this constraint is supported by
     * cipher suites with the following cipher algorithms:
     *
     * <ul>
     * <li> 3DES_EDE_CBC
     * <li> AES_128_CBC
     * <li> AES_256_CBC
     * <li> IDEA_CBC
     * <li> RC4_128
     * </ul>
     */
    public static final ConfidentialityStrength STRONG =
	new ConfidentialityStrength(true);

    /**
     * If confidentiality of message contents is ensured, then use weak
     * confidentiality for message contents. <p>
     *
     * For the endpoints in this package, this constraint is supported by
     * cipher suites with the following cipher algorithms:
     *
     * <ul>
     * <li> DES40_CBC
     * <li> DES_CBC
     * <li> RC2_CBC_40
     * <li> RC4_40
     * </ul>
     */
    public static final ConfidentialityStrength WEAK =
	new ConfidentialityStrength(false);

    /**
     * <code>true</code> for <code>STRONG</code>, <code>false</code> for
     * <code>WEAK</code>
     *
     * @serial
     */
    private final boolean value;

    /* -- Methods -- */

    /**
     * Simple constructor.
     *
     * @param val <code>true</code> for <code>STRONG</code>, <code>false</code>
     *	      for <code>WEAK</code>
     */
    private ConfidentialityStrength(boolean value) {
	this.value = value;
    }

    /** Returns a string representation of this object. */
    public String toString() {
	return value
	    ? "ConfidentialityStrength.STRONG"
	    : "ConfidentialityStrength.WEAK"; 
    }

    /** Canonicalize so that <code>==</code> can be used. */
    private Object readResolve() {
	return value ? STRONG : WEAK;
    }
}
