github.com/zmap/zlint@v1.1.0/lints/lint_qcstatem_qcretentionperiod_valid.go (about) 1 /* 2 * ZLint Copyright 2017 Regents of the University of Michigan 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 * use this file except in compliance with the License. You may obtain a copy 6 * of the License at http://www.apache.org/licenses/LICENSE-2.0 7 8 * Unless required by applicable law or agreed to in writing, software 9 * distributed under the License is distributed on an "AS IS" BASIS, 10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 11 * implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 15 package lints 16 17 import ( 18 "encoding/asn1" 19 "github.com/zmap/zcrypto/x509" 20 "github.com/zmap/zlint/util" 21 ) 22 23 type qcStatemQcRetentionPeriodValid struct{} 24 25 func (this *qcStatemQcRetentionPeriodValid) getStatementOid() *asn1.ObjectIdentifier { 26 return &util.IdEtsiQcsQcRetentionPeriod 27 } 28 29 func (l *qcStatemQcRetentionPeriodValid) Initialize() error { 30 return nil 31 } 32 33 func (l *qcStatemQcRetentionPeriodValid) CheckApplies(c *x509.Certificate) bool { 34 if !util.IsExtInCert(c, util.QcStateOid) { 35 return false 36 } 37 if util.ParseQcStatem(util.GetExtFromCert(c, util.QcStateOid).Value, *l.getStatementOid()).IsPresent() { 38 return true 39 } 40 return false 41 } 42 43 func (l *qcStatemQcRetentionPeriodValid) Execute(c *x509.Certificate) *LintResult { 44 45 errString := "" 46 ext := util.GetExtFromCert(c, util.QcStateOid) 47 s := util.ParseQcStatem(ext.Value, *l.getStatementOid()) 48 errString += s.GetErrorInfo() 49 if len(errString) == 0 { 50 51 rp := s.(util.EtsiQcRetentionPeriod) 52 if rp.Period < 0 { 53 util.AppendToStringSemicolonDelim(&errString, "retention period is negative") 54 } 55 } 56 if len(errString) == 0 { 57 return &LintResult{Status: Pass} 58 } else { 59 return &LintResult{Status: Error, Details: errString} 60 } 61 } 62 63 func init() { 64 RegisterLint(&Lint{ 65 Name: "e_qcstatem_qcretentionperiod_valid", 66 Description: "Checks that a QC Statement of the type id-etsi-qcs-QcRetentionPeriod has the correct form", 67 Citation: "ETSI EN 319 412 - 5 V2.2.1 (2017 - 11)/ Section 4.3.3", 68 Source: EtsiEsi, 69 EffectiveDate: util.EtsiEn319_412_5_V2_2_1_Date, 70 Lint: &qcStatemQcRetentionPeriodValid{}, 71 }) 72 }