001/*
002 * oauth2-oidc-sdk
003 *
004 * Copyright 2012-2021, Connect2id Ltd and contributors.
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use
007 * this file except in compliance with the License. You may obtain a copy of the
008 * License at
009 *
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software distributed
013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
015 * specific language governing permissions and limitations under the License.
016 */
017
018package com.nimbusds.openid.connect.sdk.assurance.evidences.attachment;
019
020
021import java.util.Objects;
022
023import com.nimbusds.common.contenttype.ContentType;
024import com.nimbusds.jose.util.Base64;
025
026
027/**
028 * Content with type and optional description.
029 */
030public class Content {
031        
032        
033        /**
034         * The content type.
035         */
036        private final ContentType type;
037        
038        
039        /**
040         * The BASE64-encoded content.
041         */
042        private final Base64 base64;
043        
044        
045        /**
046         * The optional description.
047         */
048        private final String description;
049        
050        
051        /**
052         * Creates a new content instance.
053         *
054         * @param type        The content type. Must not be {@code null}.
055         * @param base64      The BASE64-encoded content. Must not be
056         *                    {@code null}.
057         * @param description The optional description, {@code null} if not
058         *                    specified.
059         */
060        public Content(final ContentType type,
061                       final Base64 base64,
062                       final String description) {
063                
064                Objects.requireNonNull(type);
065                this.type = type;
066                
067                Objects.requireNonNull(base64);
068                this.base64 = base64;
069                
070                this.description = description;
071        }
072        
073        
074        /**
075         * Returns the content type.
076         *
077         * @return The content type.
078         */
079        public ContentType getType() {
080                return type;
081        }
082        
083        
084        /**
085         * Returns the BASE64-encoded content.
086         *
087         * @return The BASE64-encoded content.
088         */
089        public Base64 getBase64() {
090                return base64;
091        }
092        
093        
094        /**
095         * Returns the optional description.
096         *
097         * @return The optional description, {@code null} if not specified.
098         */
099        public String getDescription() {
100                return description;
101        }
102        
103        
104        @Override
105        public boolean equals(Object o) {
106                if (this == o) return true;
107                if (!(o instanceof Content)) return false;
108                Content content = (Content) o;
109                return getType().equals(content.getType()) &&
110                        getBase64().equals(content.getBase64()) &&
111                        Objects.equals(getDescription(), content.getDescription());
112        }
113        
114        
115        @Override
116        public int hashCode() {
117                return Objects.hash(getType(), getBase64(), getDescription());
118        }
119}