Cleanup encryption key setting by moving core to file.

This commit is contained in:
Renaud 2013-06-10 17:03:32 +08:00
parent a3b5257bfe
commit fb395c3f01
7 changed files with 50 additions and 48 deletions

39
crypt.c
View File

@ -9,47 +9,12 @@
* written by Dana Hoggatt and Daniel Lawrence
*/
#include <stdio.h>
#include "display.h"
#include "estruct.h"
#include "edef.h"
#include "input.h"
#if CRYPT
#include <stdio.h>
static int mod95(int);
/*
* reset encryption key of current buffer
*
* int f; default flag
* int n; numeric argument
*/
int set_encryption_key(int f, int n)
{
int status; /* return status */
int odisinp; /* original vlaue of disinp */
char key[NPAT]; /* new encryption string */
/* turn command input echo off */
odisinp = disinp;
disinp = FALSE;
/* get the string to use as an encrytion string */
status = mlreply("Encryption String: ", key, NPAT - 1);
disinp = odisinp;
if (status != TRUE)
return status;
/* and encrypt it */
myencrypt((char *) NULL, 0);
myencrypt(key, strlen(key));
/* and save it off */
strcpy(curbp->b_key, key);
mlwrite(" "); /* clear it off the bottom line */
return TRUE;
}
/**********
*

View File

@ -1,7 +1,10 @@
#ifndef _CRYPT_H_
#define _CRYPT_H_
int set_encryption_key( int f, int n) ;
#include "estruct.h"
#if CRYPT
void myencrypt( char *bptr, unsigned len) ;
#endif
#endif

View File

@ -12,7 +12,6 @@
#include "bind.h"
#include "bindable.h"
#include "buffer.h"
#include "crypt.h"
#include "eval.h"
#include "exec.h"
#include "file.h"

41
file.c
View File

@ -119,6 +119,41 @@ int viewfile(int f, int n)
}
#if CRYPT
void cryptbufferkey( struct buffer *bp) {
myencrypt( (char *) NULL, 0) ;
myencrypt( bp->b_key, strlen( bp->b_key)) ;
}
/*
* reset encryption key of current buffer
*
* int f; default flag
* int n; numeric argument
*/
int set_encryption_key(int f, int n)
{
int status; /* return status */
int odisinp; /* original vlaue of disinp */
char key[NPAT]; /* new encryption string */
/* turn command input echo off */
odisinp = disinp;
disinp = FALSE;
/* get the string to use as an encrytion string */
status = mlreply("Encryption String: ", key, NPAT - 1);
disinp = odisinp;
if (status != TRUE)
return status;
/* save it off and encrypt it*/
strcpy(curbp->b_key, key);
cryptbufferkey( curbp) ;
mlwrite(" "); /* clear it off the bottom line */
return TRUE;
}
static int resetkey(void)
{ /* reset the encryption key if needed */
int s; /* return status */
@ -139,12 +174,10 @@ static int resetkey(void)
/* and set up the key to be used! */
/* de-encrypt it */
myencrypt((char *) NULL, 0);
myencrypt(curbp->b_key, strlen(curbp->b_key));
cryptbufferkey( curbp) ;
/* re-encrypt it...seeding it to start */
myencrypt((char *) NULL, 0);
myencrypt(curbp->b_key, strlen(curbp->b_key));
cryptbufferkey( curbp) ;
}
return TRUE;

5
file.h
View File

@ -1,6 +1,11 @@
#ifndef _FILE_H_
#define _FILE_H_
#if CRYPT
void cryptbufferkey( struct buffer *bp) ;
int set_encryption_key( int f, int n) ;
#endif
int fileread( int f, int n) ;
int insfile( int f, int n) ;
int filefind( int f, int n) ;

6
main.c
View File

@ -61,7 +61,6 @@
#include "bind.h"
#include "bindable.h"
#include "buffer.h"
#include "crypt.h"
#include "display.h"
#include "edef.h" /* Global definitions. */
#include "estruct.h" /* Global structures and defines. */
@ -269,9 +268,8 @@ int main(int argc, char **argv)
#if CRYPT
if (cryptflag) {
bp->b_mode |= MDCRYPT;
myencrypt((char *) NULL, 0);
myencrypt(ekey, strlen(ekey));
strncpy(bp->b_key, ekey, NPAT);
strncpy( bp->b_key, ekey, NPAT) ;
cryptbufferkey( bp) ;
}
#endif
}

View File

@ -15,7 +15,6 @@
#include "display.h"
#include "eval.h"
#include "exec.h"
#include "crypt.h"
#include "file.h"
#include "isearch.h"
#include "line.h"