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 org.bouncycastle.asn1.x500.X500Name;
24 import org.bouncycastle.asn1.x509.GeneralName;
26 import java.util.Arrays;
27 import java.util.Collections;
28 import java.util.Comparator;
29 import java.util.List;
30 import java.util.Objects;
31 import java.util.stream.Collectors;
33 public class CertificateData {
35 private final X500Name subject;
36 private final List<GeneralName> sortedSans;
38 public CertificateData(X500Name subject, GeneralName[] sans) {
39 this.subject = subject;
40 this.sortedSans = sans != null ? getSortedSansList(sans) : Collections.emptyList();
43 public X500Name getSubject() {
47 public GeneralName[] getSortedSans() {
48 return sortedSans.toArray(new GeneralName[0]);
52 public boolean equals(Object o) {
53 if (this == o) return true;
54 if (o == null || getClass() != o.getClass()) return false;
55 CertificateData that = (CertificateData) o;
56 return Objects.equals(subject, that.subject) && Objects.equals(sortedSans, that.sortedSans);
60 public int hashCode() {
61 return Objects.hash(subject, sortedSans);
64 private List<GeneralName> getSortedSansList(GeneralName[] sans) {
65 return Arrays.stream(sans).sorted(Comparator.comparing(GeneralName::toString))
66 .collect(Collectors.toUnmodifiableList());