// 
// Decompiled by Procyon v0.6.0
// 

package org.bouncycastle.jcajce.util;

import java.util.HashMap;
import java.util.Collections;
import java.util.Map;
import java.security.PrivateKey;

public class AnnotatedPrivateKey implements PrivateKey
{
    public static final String LABEL = "label";
    private final PrivateKey key;
    private final Map<String, Object> annotations;
    
    AnnotatedPrivateKey(final PrivateKey key, final String value) {
        this.key = key;
        this.annotations = (Map<String, Object>)Collections.singletonMap("label", value);
    }
    
    AnnotatedPrivateKey(final PrivateKey key, final Map<String, Object> annotations) {
        this.key = key;
        this.annotations = annotations;
    }
    
    public PrivateKey getKey() {
        return this.key;
    }
    
    public Map<String, Object> getAnnotations() {
        return this.annotations;
    }
    
    @Override
    public String getAlgorithm() {
        return this.key.getAlgorithm();
    }
    
    public Object getAnnotation(final String s) {
        return this.annotations.get(s);
    }
    
    public AnnotatedPrivateKey addAnnotation(final String s, final Object o) {
        final HashMap m = new HashMap((Map<? extends K, ? extends V>)this.annotations);
        m.put(s, o);
        return new AnnotatedPrivateKey(this.key, (Map<String, Object>)Collections.unmodifiableMap((Map<?, ?>)m));
    }
    
    public AnnotatedPrivateKey removeAnnotation(final String s) {
        final HashMap m = new HashMap((Map<? extends K, ? extends V>)this.annotations);
        m.remove(s);
        return new AnnotatedPrivateKey(this.key, (Map<String, Object>)Collections.unmodifiableMap((Map<?, ?>)m));
    }
    
    @Override
    public String getFormat() {
        return this.key.getFormat();
    }
    
    @Override
    public byte[] getEncoded() {
        return this.key.getEncoded();
    }
    
    @Override
    public int hashCode() {
        return this.key.hashCode();
    }
    
    @Override
    public boolean equals(final Object obj) {
        if (obj instanceof AnnotatedPrivateKey) {
            return this.key.equals(((AnnotatedPrivateKey)obj).key);
        }
        return this.key.equals(obj);
    }
    
    @Override
    public String toString() {
        if (this.annotations.containsKey("label")) {
            return this.annotations.get("label").toString();
        }
        return this.key.toString();
    }
}
