| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Cpe |
|
| 1.25;1.25 |
| 1 | /* | |
| 2 | * This file is part of dependency-check-core. | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | * | |
| 16 | * Copyright (c) 2015 Jeremy Long. All Rights Reserved. | |
| 17 | */ | |
| 18 | package org.owasp.dependencycheck.data.update.cpe; | |
| 19 | ||
| 20 | import java.io.UnsupportedEncodingException; | |
| 21 | import java.net.URLDecoder; | |
| 22 | import org.owasp.dependencycheck.data.update.exception.InvalidDataException; | |
| 23 | ||
| 24 | /** | |
| 25 | * | |
| 26 | * @author Jeremy Long | |
| 27 | */ | |
| 28 | public class Cpe { | |
| 29 | ||
| 30 | /** | |
| 31 | * Constructs a new Cpe Object by parsing the vendor and product from the CPE identifier value. | |
| 32 | * | |
| 33 | * @param value the cpe identifier (cpe:/a:vendor:product:version:....) | |
| 34 | * @throws UnsupportedEncodingException thrown if UTF-8 is not supported | |
| 35 | * @throws InvalidDataException thrown if the CPE provided is not the correct format | |
| 36 | */ | |
| 37 | 0 | public Cpe(String value) throws UnsupportedEncodingException, InvalidDataException { |
| 38 | 0 | this.value = value; |
| 39 | 0 | final String[] data = value.substring(7).split(":"); |
| 40 | 0 | if (data.length >= 2) { |
| 41 | 0 | vendor = URLDecoder.decode(data[0].replace("+", "%2B"), "UTF-8"); |
| 42 | 0 | product = URLDecoder.decode(data[1].replace("+", "%2B"), "UTF-8"); |
| 43 | } else { | |
| 44 | 0 | throw new InvalidDataException(String.format("CPE has an invalid format: %s", value)); |
| 45 | } | |
| 46 | 0 | } |
| 47 | ||
| 48 | /** | |
| 49 | * The CPE identifier string (cpe:/a:vendor:product:version). | |
| 50 | */ | |
| 51 | private String value; | |
| 52 | ||
| 53 | /** | |
| 54 | * Get the value of value. | |
| 55 | * | |
| 56 | * @return the value of value | |
| 57 | */ | |
| 58 | public String getValue() { | |
| 59 | 0 | return value; |
| 60 | } | |
| 61 | ||
| 62 | /** | |
| 63 | * Set the value of value. | |
| 64 | * | |
| 65 | * @param value new value of value | |
| 66 | */ | |
| 67 | public void setValue(String value) { | |
| 68 | 0 | this.value = value; |
| 69 | 0 | } |
| 70 | /** | |
| 71 | * The vendor portion of the identifier. | |
| 72 | */ | |
| 73 | private String vendor; | |
| 74 | ||
| 75 | /** | |
| 76 | * Get the value of vendor. | |
| 77 | * | |
| 78 | * @return the value of vendor | |
| 79 | */ | |
| 80 | public String getVendor() { | |
| 81 | 0 | return vendor; |
| 82 | } | |
| 83 | ||
| 84 | /** | |
| 85 | * Set the value of vendor. | |
| 86 | * | |
| 87 | * @param vendor new value of vendor | |
| 88 | */ | |
| 89 | public void setVendor(String vendor) { | |
| 90 | 0 | this.vendor = vendor; |
| 91 | 0 | } |
| 92 | ||
| 93 | /** | |
| 94 | * The product portion of the identifier. | |
| 95 | */ | |
| 96 | private String product; | |
| 97 | ||
| 98 | /** | |
| 99 | * Get the value of product. | |
| 100 | * | |
| 101 | * @return the value of product | |
| 102 | */ | |
| 103 | public String getProduct() { | |
| 104 | 0 | return product; |
| 105 | } | |
| 106 | ||
| 107 | /** | |
| 108 | * Set the value of product. | |
| 109 | * | |
| 110 | * @param product new value of product | |
| 111 | */ | |
| 112 | public void setProduct(String product) { | |
| 113 | 0 | this.product = product; |
| 114 | 0 | } |
| 115 | ||
| 116 | /** | |
| 117 | * Returns the full CPE identifier. | |
| 118 | * | |
| 119 | * @return the full CPE identifier | |
| 120 | */ | |
| 121 | @Override | |
| 122 | public String toString() { | |
| 123 | 0 | return value; |
| 124 | } | |
| 125 | } |