home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / sharewar / dos / program / gs300sr1 / gs300sr1.exe / ZMISC1.C < prev    next >
C/C++ Source or Header  |  1994-07-27  |  3KB  |  95 lines

  1. /* Copyright (C) 1994 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* zmisc1.c */
  20. /* Miscellaneous Type 1 font operators */
  21. #include "memory_.h"
  22. #include "ghost.h"
  23. #include "errors.h"
  24. #include "oper.h"
  25. #include "gscrypt1.h"
  26. #include "strimpl.h"
  27. #include "sfilter.h"
  28. #include "ifilter.h"
  29.  
  30. /* <state> <from_string> <to_string> .type1encrypt <new_state> <substring> */
  31. /* <state> <from_string> <to_string> .type1decrypt <new_state> <substring> */
  32. private int type1crypt(P2(os_ptr,
  33.               int (*)(P4(byte *, const byte *, uint, ushort *))));
  34. int
  35. ztype1encrypt(os_ptr op)
  36. {    return type1crypt(op, gs_type1_encrypt);
  37. }
  38. int
  39. ztype1decrypt(os_ptr op)
  40. {    return type1crypt(op, gs_type1_decrypt);
  41. }
  42. private int
  43. type1crypt(register os_ptr op, int (*proc)(P4(byte *, const byte *, uint, ushort *)))
  44. {    crypt_state state;
  45.     uint ssize;
  46.     check_type(op[-2], t_integer);
  47.     state = op[-2].value.intval;
  48.     if ( op[-2].value.intval != state )
  49.         return_error(e_rangecheck);    /* state value was truncated */
  50.     check_read_type(op[-1], t_string);
  51.     check_write_type(*op, t_string);
  52.     ssize = r_size(op - 1);
  53.     if ( r_size(op) < ssize )
  54.         return_error(e_rangecheck);
  55.     (void) (*proc)(op->value.bytes, op[-1].value.const_bytes, ssize,
  56.                &state);        /* can't fail */
  57.     op[-2].value.intval = state;
  58.     op[-1] = *op;
  59.     r_set_size(op - 1, ssize);
  60.     pop(1);
  61.     return 0;
  62. }
  63.  
  64. /* <target> <seed> .filter_eexecEncode <file> */
  65. int
  66. zexE(register os_ptr op)
  67. {    stream_exE_state state;
  68.     check_type(*op, t_integer);
  69.     state.cstate = op->value.intval;
  70.     if ( op->value.intval != state.cstate )
  71.         return_error(e_rangecheck);    /* state value was truncated */
  72.     return filter_write(op, 1, &s_exE_template, (stream_state *)&state, false);
  73. }
  74.  
  75. /* <source> <seed> .filter_eexecDecode <file> */
  76. int
  77. zexD(register os_ptr op)
  78. {    stream_exD_state state;
  79.     check_type(*op, t_integer);
  80.     state.cstate = op->value.intval;
  81.     if ( op->value.intval != state.cstate )
  82.         return_error(e_rangecheck);    /* state value was truncated */
  83.     return filter_read(op, 1, &s_exD_template, (stream_state *)&state, false);
  84. }
  85.  
  86. /* ------ Initialization procedure ------ */
  87.  
  88. op_def zmisc1_op_defs[] = {
  89.     {"2.filter_eexecEncode", zexE},
  90.     {"2.filter_eexecDecode", zexD},
  91.     {"3.type1encrypt", ztype1encrypt},
  92.     {"3.type1decrypt", ztype1decrypt},
  93.     op_def_end(0)
  94. };
  95.