home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / libmime / mimemsig.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.5 KB  |  149 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /* mimemsig.h --- definition of the MimeMultipartSigned class (see mimei.h)
  20.    Created: Jamie Zawinski <jwz@netscape.com>, 23-Sep-96.
  21.  */
  22.  
  23. #ifndef _MIMEMSIG_H_
  24. #define _MIMEMSIG_H_
  25.  
  26. #include "mimemult.h"
  27. #include "mimepbuf.h"
  28. #include "mimeenc.h"
  29.  
  30. /* The MimeMultipartSigned class implements the multipart/signed MIME
  31.    container, which provides a general method of associating a cryptographic
  32.    signature to an arbitrary MIME object.
  33.  
  34.    The MimeMultipartSigned class provides the following methods:
  35.  
  36.    void *crypto_init (MimeObject *multipart_object)
  37.  
  38.      This is called with the object, the object->headers of which should be
  39.      used to initialize the decryption engine.  NULL indicates failure;
  40.      otherwise, an opaque closure object should be returned.
  41.  
  42.    int crypto_data_hash (char *data, int32 data_size, 
  43.                          void *crypto_closure)
  44.  
  45.      This is called with the raw data, for which a signature has been computed.
  46.      The crypto module should examine this, and compute a signature for it.
  47.  
  48.    int crypto_data_eof (void *crypto_closure, XP_Bool abort_p)
  49.  
  50.      This is called when no more data remains.  If `abort_p' is true, then the
  51.      crypto module may choose to discard any data rather than processing it,
  52.      as we're terminating abnormally.
  53.  
  54.    int crypto_signature_init (void *crypto_closure,
  55.                               MimeObject *multipart_object,
  56.                               MimeHeaders *signature_hdrs)
  57.  
  58.      This is called after crypto_data_eof() and just before the first call to
  59.      crypto_signature_hash().  The crypto module may wish to do some
  60.      initialization here, or may wish to examine the actual headers of the
  61.      signature object itself.
  62.  
  63.    int crypto_signature_hash (char *data, int32 data_size,
  64.                               void *crypto_closure)
  65.  
  66.      This is called with the raw data of the detached signature block.  It will
  67.      be called after crypto_data_eof() has been called to signify the end of
  68.      the data which is signed.  This data is the data of the signature itself.
  69.  
  70.    int crypto_signature_eof (void *crypto_closure, XP_Bool abort_p)
  71.  
  72.      This is called when no more signature data remains.  If `abort_p' is true,
  73.      then the crypto module may choose to discard any data rather than
  74.      processing it, as we're terminating abnormally.
  75.  
  76.    char * crypto_generate_html (void *crypto_closure)
  77.  
  78.      This is called after `crypto_signature_eof' but before `crypto_free'.
  79.      The crypto module should return a newly-allocated string of HTML code
  80.      which explains the status of the decryption to the user (whether the
  81.      signature checks out, etc.)
  82.  
  83.    void crypto_free (void *crypto_closure)
  84.  
  85.      This will be called when we're all done, after `crypto_signature_eof' and
  86.      `crypto_emit_html'.  It is intended to free any data represented by the
  87.      crypto_closure.
  88.  */
  89.  
  90. typedef struct MimeMultipartSignedClass MimeMultipartSignedClass;
  91. typedef struct MimeMultipartSigned      MimeMultipartSigned;
  92.  
  93. typedef enum {
  94.   MimeMultipartSignedPreamble,
  95.   MimeMultipartSignedBodyFirstHeader,
  96.   MimeMultipartSignedBodyHeaders,
  97.   MimeMultipartSignedBodyFirstLine,
  98.   MimeMultipartSignedBodyLine,
  99.   MimeMultipartSignedSignatureHeaders,
  100.   MimeMultipartSignedSignatureFirstLine,
  101.   MimeMultipartSignedSignatureLine,
  102.   MimeMultipartSignedEpilogue
  103. } MimeMultipartSignedParseState;
  104.  
  105. struct MimeMultipartSignedClass {
  106.   MimeMultipartClass multipart;
  107.  
  108.   /* Callbacks used by decryption (really, signature verification) module. */
  109.   void * (*crypto_init) (MimeObject *multipart_object);
  110.  
  111.   int (*crypto_data_hash)      (char *data, int32 data_size,
  112.                                 void *crypto_closure);
  113.   int (*crypto_signature_hash) (char *data, int32 data_size,
  114.                                 void *crypto_closure);
  115.  
  116.   int (*crypto_data_eof)      (void *crypto_closure, XP_Bool abort_p);
  117.   int (*crypto_signature_eof) (void *crypto_closure, XP_Bool abort_p);
  118.  
  119.   int (*crypto_signature_init) (void *crypto_closure,
  120.                                 MimeObject *multipart_object,
  121.                                 MimeHeaders *signature_hdrs);
  122.  
  123.   char * (*crypto_generate_html) (void *crypto_closure);
  124.  
  125.   void (*crypto_free) (void *crypto_closure);
  126. };
  127.  
  128. extern MimeMultipartSignedClass mimeMultipartSignedClass;
  129.  
  130. struct MimeMultipartSigned {
  131.   MimeMultipart multipart;
  132.   MimeMultipartSignedParseState state;    /* State of parser */
  133.  
  134.   void *crypto_closure;                     /* Opaque data used by signature
  135.                                             verification module. */
  136.  
  137.   MimeHeaders *body_hdrs;                /* The headers of the signed object. */
  138.   MimeHeaders *sig_hdrs;                /* The headers of the signature. */
  139.  
  140.   MimePartBufferData *part_buffer;        /* The buffered body of the signed
  141.                                            object (see mimepbuf.h) */
  142.  
  143.   MimeDecoderData *sig_decoder_data;    /* The signature is probably base64
  144.                                            encoded; this is the decoder used
  145.                                            to get raw bits out of it. */
  146. };
  147.  
  148. #endif /* _MIMEMSIG_H_ */
  149.