Ejemplo n.º 1
0
 static void extract(uint index, string file)
 {
     digidoc.digidoc.initialize();
     try
     {
         Console.WriteLine("Opening file: " + file);
         WDoc b = new WDoc(file);
         if (index < b.documentCount())
         {
             Document d = b.getDocument(index);
             string dest = Path.Combine(Directory.GetCurrentDirectory(), d.getFileName());
             Console.WriteLine("Extracting file {0} to {1}", d.getFileName(), dest);
             try
             {
                 File.Copy(d.getFilePath(), dest);
             }
             catch (Exception e)
             {
                 Console.WriteLine("Failed to copy file");
                 Console.WriteLine(e.Message);
             }
         }
         else
             Console.WriteLine("No such document");
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
     digidoc.digidoc.terminate();
 }
Ejemplo n.º 2
0
 internal static HandleRef getCPtr(WDoc obj)
 {
     return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }
Ejemplo n.º 3
0
        static void verify(string file)
        {
            digidoc.digidoc.initialize();
            try
            {
                Console.WriteLine("Opening file: " + file);
                WDoc b = new WDoc(file);

                Console.WriteLine("Files:");
                for (uint i = 0; i < b.documentCount(); ++i)
                {
                    Document d = b.getDocument(i);
                    Console.WriteLine(" {0} - {1}", i, d.getFileName());
                }
                Console.WriteLine();

                Console.WriteLine("Signatures:");
                for (uint i = 0; i < b.signatureCount(); ++i)
                {
                    Signature s = b.getSignature(i);

                    SignatureProductionPlace p = s.getProductionPlace();
                    Console.WriteLine("Address: {0} {1} {2} {3}", p.city, p.countryName, p.stateOrProvince, p.postalCode);

                    SignerRole r = s.getSignerRole();
                    Console.Write("Role:");
                    for (int j = 0; j < r.claimedRoles.Count; ++j)
                        Console.Write(" " + r.claimedRoles[j]);
                    Console.WriteLine();

                    Console.WriteLine("Time: " + s.getSigningTime());

                    System.Security.Cryptography.X509Certificates.X509Certificate2 c =
                        new System.Security.Cryptography.X509Certificates.X509Certificate2(s.getSigningCert());
                    Console.WriteLine("Cert: " + c.Subject);
                    try
                    {
                        s.validateOffline();
                        Console.WriteLine("Signature is valid");
                    }
                    catch (DigidocSignatureException e)
                    {
                        Console.WriteLine("Signature is invalid");
                        Console.WriteLine(e.Message);
                    }
                }
            }
            catch (DigidocBDocException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (DigidocIOException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (DigidocSignException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (DigidocSignatureException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (DigidocException e)
            {
                Console.WriteLine(e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            digidoc.digidoc.terminate();
        }