2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2021 Nokia. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.oom.certservice.certification.model;
23 import java.util.Arrays;
24 import java.util.Collections;
25 import java.util.Comparator;
26 import java.util.List;
27 import java.util.Objects;
28 import java.util.stream.Collectors;
29 import org.bouncycastle.asn1.x500.X500Name;
30 import org.bouncycastle.asn1.x509.GeneralName;
32 public class CertificateData {
34 private final X500Name subject;
35 private final List<GeneralName> sortedSans;
37 public CertificateData(X500Name subject, GeneralName[] sans) {
38 this.subject = subject;
39 this.sortedSans = sans != null ? getSortedSansList(sans) : Collections.emptyList();
42 public X500Name getSubject() {
46 public GeneralName[] getSortedSans() {
47 return sortedSans.toArray(new GeneralName[0]);
51 public boolean equals(Object obj) {
55 if (obj == null || getClass() != obj.getClass()) {
58 CertificateData that = (CertificateData) obj;
59 return Objects.equals(subject, that.subject) && Objects.equals(sortedSans, that.sortedSans);
63 public int hashCode() {
64 return Objects.hash(subject, sortedSans);
67 private List<GeneralName> getSortedSansList(GeneralName[] sans) {
68 return Arrays.stream(sans).sorted(Comparator.comparing(GeneralName::toString))
69 .collect(Collectors.toUnmodifiableList());