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 com.nimbusds.oauth2.sdk.ParseException; 022import com.nimbusds.oauth2.sdk.util.StringUtils; 023 024 025/** 026 * Evidence attachment type. 027 * 028 * <p>Related specifications: 029 * 030 * <ul> 031 * <li>OpenID Connect for Identity Assurance 1.0, section 5.1.2 and 9. 032 * </ul> 033 */ 034public enum AttachmentType { 035 036 037 /** 038 * Embedded attachment. 039 */ 040 EMBEDDED, 041 042 043 /** 044 * External attachment. 045 */ 046 EXTERNAL; 047 048 049 @Override 050 public String toString() { 051 return name().toLowerCase(); 052 } 053 054 055 /** 056 * Parses an attachment type from the specified string. 057 * 058 * @param s The string to parse. Must not be {@code null}. 059 * 060 * @return The attachment type. 061 * 062 * @throws ParseException If parsing failed. 063 */ 064 public static AttachmentType parse(final String s) 065 throws ParseException { 066 067 if (StringUtils.isBlank(s)) { 068 throw new ParseException("Null or blank attachment type"); 069 } 070 071 if (EMBEDDED.name().equalsIgnoreCase(s)) { 072 return EMBEDDED; 073 } else if (EXTERNAL.name().equalsIgnoreCase(s)) { 074 return EXTERNAL; 075 } else { 076 throw new ParseException("Invalid attachment type: " + s); 077 } 078 } 079}