Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
The BSD License Copyright (c) 2010-2012 RIPE NCC All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the RIPE NCC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 package net.ripe.rpki.commons.crypto.cms.manifest;
 
 
 import java.util.Map;
 
 import static net.ripe.rpki.commons.crypto.util.Asn1Util.*;
 import static net.ripe.rpki.commons.validation.ValidationString.*;

See:
http://tools.ietf.org/html/draft-ietf-sidr-rpki-manifests-07
 
 
 public class ManifestCmsParser extends RpkiSignedObjectParser {
 
     private int version = .;
 
     private static final int MANIFEST_CONTENT_SEQUENCE_LENGTH = 5;
     private static final int MANIFEST_NUMBER_INDEX = 0;
     private static final int THIS_UPDATE_TIME_INDEX = 1;
     private static final int NEXT_UPDATE_TIME_INDEX = 2;
     private static final int FILE_HASH_ALGORHYTHM_INDEX = 3;
     private static final int FILE_LIST_INDEX = 4;
 
     private BigInteger number;
 
     private DateTime thisUpdateTime;
 
     private DateTime nextUpdateTime;
 
     private String fileHashAlgorithm;
 
     private Map<Stringbyte[]> files;
 
     @Override
     public void parse(ValidationResult resultbyte[] encoded) {
         super.parse(resultencoded);
         if (isSuccess()) {
             validateManifest();
         }
     }
 
     public boolean isSuccess() {
         return !getValidationResult().hasFailures();
     }
 
     public ManifestCms getManifestCms() {
         if (!isSuccess()) {
             throw new IllegalArgumentException("Manifest validation failed: " + getValidationResult().getFailuresForCurrentLocation());
         }
 
         return new ManifestCms(cmsObjectDatamanifestCmsGeneralInfo);
     }
    private void validateManifest() {
        ValidationResult validationResult = getValidationResult();
    }
    void decodeManifest(ASN1Encodable encoded) {
        ValidationResult validationResult = getValidationResult();
        try {
            ASN1Sequence seq = expect(encodedASN1Sequence.class);
            validationResult.rejectIfFalse(seq.size() == );
            if (validationResult.hasFailureForCurrentLocation()) {
                return;
            }
             = .;
             = expect(seq.getObjectAt(), ASN1Integer.class).getValue();
             = new TreeMap<Stringbyte[]>();
            decodeFileList(seq.getObjectAt());
        } catch (IllegalArgumentException e) {
            validationResult.error();
        } catch (ParseException e) {
            validationResult.error();
        }
    }
    void decodeFileAndHash(Map<Stringbyte[]> resultASN1Encodable encoded) {
        ASN1Sequence seq = expect(encodedASN1Sequence.class);
        Validate.isTrue(seq.size() == 2, "der sequence does not contain file and hash");
        DERIA5String derFile = expect(seq.getObjectAt(0), DERIA5String.class);
        DERBitString derHash = expect(seq.getObjectAt(1), DERBitString.class);
        result.put(derFile.getString(), derHash.getBytes());
    }
    void decodeFileList(Map<Stringbyte[]> resultASN1Encodable encoded) {
        ASN1Sequence seq = expect(encodedASN1Sequence.class);
        boolean errorOccured = false;
        for (int i = 0; i < seq.size(); ++i) {
            try {
                decodeFileAndHash(resultseq.getObjectAt(i));
            } catch (IllegalArgumentException e) {
                errorOccured = true;
                break;
            }
        }
    }
    @Override
    public void decodeContent(ASN1Encodable encoded) {
        decodeManifest(encoded);
    }
New to GrepCode? Check out our FAQ X