Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.asn1.cms;
  
  
RFC 5652 section 9.1: The AuthenticatedData carries AuthAttributes and other data which define what really is being signed.

 AuthenticatedData ::= SEQUENCE {
       version CMSVersion,
       originatorInfo [0] IMPLICIT OriginatorInfo OPTIONAL,
       recipientInfos RecipientInfos,
       macAlgorithm MessageAuthenticationCodeAlgorithm,
       digestAlgorithm [1] DigestAlgorithmIdentifier OPTIONAL,
       encapContentInfo EncapsulatedContentInfo,
       authAttrs [2] IMPLICIT AuthAttributes OPTIONAL,
       mac MessageAuthenticationCode,
       unauthAttrs [3] IMPLICIT UnauthAttributes OPTIONAL }

 AuthAttributes ::= SET SIZE (1..MAX) OF Attribute

 UnauthAttributes ::= SET SIZE (1..MAX) OF Attribute

 MessageAuthenticationCode ::= OCTET STRING
 
 
 public class AuthenticatedData
     extends ASN1Object
 {
     private ASN1Integer version;
     private OriginatorInfo originatorInfo;
     private ASN1Set recipientInfos;
     private AlgorithmIdentifier macAlgorithm;
     private ASN1Set authAttrs;
     private ASN1OctetString mac;
     private ASN1Set unauthAttrs;
 
     public AuthenticatedData(
         OriginatorInfo originatorInfo,
         ASN1Set recipientInfos,
         AlgorithmIdentifier macAlgorithm,
         AlgorithmIdentifier digestAlgorithm,
         ContentInfo encapsulatedContent,
         ASN1Set authAttrs,
         ASN1OctetString mac,
         ASN1Set unauthAttrs)
     {
         if (digestAlgorithm != null || authAttrs != null)
         {
             if (digestAlgorithm == null || authAttrs == null)
             {
                 throw new IllegalArgumentException("digestAlgorithm and authAttrs must be set together");
             }
         }
 
          = new ASN1Integer(calculateVersion(originatorInfo));
         
         this. = originatorInfo;
         this. = macAlgorithm;
         this. = digestAlgorithm;
         this. = recipientInfos;
         this. = encapsulatedContent;
         this. = authAttrs;
         this. = mac;
         this. = unauthAttrs;
     }

    

Deprecated:
use getInstance()
 
     public AuthenticatedData(
         ASN1Sequence seq)
     {
         int index = 0;
 
          = (ASN1Integer)seq.getObjectAt(index++);
 
         Object tmp = seq.getObjectAt(index++);
 
         if (tmp instanceof ASN1TaggedObject)
         {
              = OriginatorInfo.getInstance((ASN1TaggedObject)tmpfalse);
             tmp = seq.getObjectAt(index++);
        }
         = ASN1Set.getInstance(tmp);
         = AlgorithmIdentifier.getInstance(seq.getObjectAt(index++));
        tmp = seq.getObjectAt(index++);
        if (tmp instanceof ASN1TaggedObject)
        {
             = AlgorithmIdentifier.getInstance((ASN1TaggedObject)tmpfalse);
            tmp = seq.getObjectAt(index++);
        }
         = ContentInfo.getInstance(tmp);
        tmp = seq.getObjectAt(index++);
        if (tmp instanceof ASN1TaggedObject)
        {
             = ASN1Set.getInstance((ASN1TaggedObject)tmpfalse);
            tmp = seq.getObjectAt(index++);
        }
         = ASN1OctetString.getInstance(tmp);
        
        if (seq.size() > index)
        {
             = ASN1Set.getInstance((ASN1TaggedObject)seq.getObjectAt(index), false);
        }
    }

    
Return an AuthenticatedData object from a tagged object.

Parameters:
obj the tagged object holding the object we want.
explicit true if the object is meant to be explicitly tagged false otherwise.
Throws:
java.lang.IllegalArgumentException if the object held by the tagged object cannot be converted.
    public static AuthenticatedData getInstance(
        ASN1TaggedObject obj,
        boolean explicit)
    {
        return getInstance(ASN1Sequence.getInstance(objexplicit));
    }

    
Return an AuthenticatedData object from the given object.

Accepted inputs:

  • null → null
  • AuthenticatedData object
  • ASN1Sequence input formats with AuthenticatedData structure inside

Parameters:
obj the object we want converted.
Throws:
java.lang.IllegalArgumentException if the object cannot be converted.
    public static AuthenticatedData getInstance(
        Object obj)
    {
        if (obj == null || obj instanceof AuthenticatedData)
        {
            return (AuthenticatedData)obj;
        }
        if (obj instanceof ASN1Sequence)
        {
            return new AuthenticatedData((ASN1Sequence)obj);
        }
        throw new IllegalArgumentException("Invalid AuthenticatedData: " + obj.getClass().getName());
    }
    public ASN1Integer getVersion()
    {
        return ;
    }
    {
        return ;
    }
    public ASN1Set getRecipientInfos()
    {
        return ;
    }
    {
        return ;
    }
    {
        return ;
    }
    {
        return ;
    }
    public ASN1Set getAuthAttrs()
    {
        return ;
    }
    public ASN1OctetString getMac()
    {
        return ;
    }
    public ASN1Set getUnauthAttrs()
    {
        return ;
    }

    
Produce an object suitable for an ASN1OutputStream.
    {
        ASN1EncodableVector v = new ASN1EncodableVector();
        v.add();
        if ( != null)
        {
            v.add(new DERTaggedObject(false, 0, ));
        }
        v.add();
        v.add();
        if ( != null)
        {
            v.add(new DERTaggedObject(false, 1, ));
        }
        v.add();
        if ( != null)
        {
            v.add(new DERTaggedObject(false, 2, ));
        }
        v.add();
        if ( != null)
        {
            v.add(new DERTaggedObject(false, 3, ));
        }
        return new BERSequence(v);
    }
    public static int calculateVersion(OriginatorInfo origInfo)
    {
        if (origInfo == null)
        {
            return 0;
        }
        else
        {
            int ver = 0;
            for (Enumeration e = origInfo.getCertificates().getObjects(); e.hasMoreElements();)
            {
                Object obj = e.nextElement();
                if (obj instanceof ASN1TaggedObject)
                {
                    ASN1TaggedObject tag = (ASN1TaggedObject)obj;
                    if (tag.getTagNo() == 2)
                    {
                        ver = 1;
                    }
                    else if (tag.getTagNo() == 3)
                    {
                        ver = 3;
                        break;
                    }
                }
            }
            if (origInfo.getCRLs() != null)
            {
                for (Enumeration e = origInfo.getCRLs().getObjects(); e.hasMoreElements();)
                {
                    Object obj = e.nextElement();
                    if (obj instanceof ASN1TaggedObject)
                    {
                        ASN1TaggedObject tag = (ASN1TaggedObject)obj;
                        if (tag.getTagNo() == 1)
                        {
                            ver = 3;
                            break;
                        }
                    }
                }
            }
            return ver;
        }
    }
New to GrepCode? Check out our FAQ X