001    package com.nimbusds.jose;
002    
003    
004    import java.util.Map;
005    import java.util.Set;
006    
007    import net.minidev.json.JSONObject;
008    
009    import com.nimbusds.jose.util.Base64URL;
010    
011    
012    /**
013     * Read-only view of a {@link Header header}.
014     *
015     * @author Vladimir Dzhuvinov
016     * @version $version$ (2013-04-15)
017     */
018    public interface ReadOnlyHeader {
019    
020    
021            /**
022             * Gets the algorithm ({@code alg}) parameter.
023             *
024             * @return The algorithm parameter.
025             */
026            public Algorithm getAlgorithm();
027    
028    
029            /**
030             * Gets the type ({@code typ}) parameter.
031             *
032             * @return The type parameter, {@code null} if not specified.
033             */
034            public JOSEObjectType getType();
035    
036    
037            /**
038             * Gets the content type ({@code cty}) parameter.
039             *
040             * @return The content type parameter, {@code null} if not specified.
041             */
042            public String getContentType();
043    
044    
045            /**
046             * Gets a custom (non-reserved) parameter.
047             *
048             * @param name The name of the custom parameter. Must not be 
049             *             {@code null}.
050             *
051             * @return The custom parameter, {@code null} if not specified.
052             */
053            public Object getCustomParameter(final String name);
054    
055    
056            /**
057             * Gets the custom (non-reserved) parameters.
058             *
059             * @return The custom parameters, as a unmodifiable map, empty map if 
060             *         none.
061             */
062            public Map<String,Object> getCustomParameters();
063    
064    
065            /**
066             * Gets the names of all included parameters (reserved and custom) in 
067             * the header instance.
068             *
069             * @return The included parameters.
070             */
071            public Set<String> getIncludedParameters();
072    
073    
074            /**
075             * Returns a JSON object representation of the header. All custom
076             * parameters are included if they serialise to a JSON entity and 
077             * their names don't conflict with the reserved ones.
078             *
079             * @return The JSON object representation of the header.
080             */
081            public JSONObject toJSONObject();
082    
083    
084            /**
085             * Returns a JSON string representation of the header. All custom
086             * parameters will be included if they serialise to a JSON entity and 
087             * their names don't conflict with the reserved ones.
088             *
089             * @return The JSON string representation of the header.
090             */
091            public String toString();
092    
093    
094            /**
095             * Returns a Base64URL representation of the header. If the header was
096             * parsed always returns the original Base64URL (required for JWS
097             * validation and authenticated JWE decryption).
098             *
099             * @return The original parsed Base64URL representation of the header,
100             *         or a new Base64URL representation if the header was created
101             *         from scratch.
102             */
103            public Base64URL toBase64URL();
104    }