mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-05 16:00:05 +01:00
git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@348 36d66b0a-2a48-0410-832c-cd162a569da5
43 lines
926 B
C
43 lines
926 B
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
|
|
#include "internal.h"
|
|
|
|
int crypt_parse_name_and_mode(const char *s, char *cipher, char *cipher_mode)
|
|
{
|
|
if (sscanf(s, "%" MAX_CIPHER_LEN_STR "[^-]-%" MAX_CIPHER_LEN_STR "s",
|
|
cipher, cipher_mode) == 2) {
|
|
return 0;
|
|
}
|
|
|
|
if (sscanf(s, "%" MAX_CIPHER_LEN_STR "[^-]", cipher) == 1) {
|
|
strncpy(cipher_mode, "cbc-plain", 9);
|
|
return 0;
|
|
}
|
|
|
|
return -EINVAL;
|
|
}
|
|
|
|
#if 0
|
|
/* Token content stringification, see info cpp/stringification */
|
|
#define str(s) #s
|
|
#define xstr(s) str(s)
|
|
#define scanpattern1 "%" xstr(MAX_CIPHER_LEN) "[^-]-%" xstr(MAX_CIPHER_LEN) "s"
|
|
#define scanpattern2 "%" xstr(MAX_CIPHER_LEN) "[^-]"
|
|
|
|
if(sscanf(nameAndMode,scanpattern1, name, mode) != 2) {
|
|
if((r = sscanf(nameAndMode,scanpattern2,name)) == 1)
|
|
strncpy(mode,"cbc-plain",10);
|
|
else
|
|
return -EINVAL;
|
|
}
|
|
|
|
return 0;
|
|
|
|
#undef scanpattern1
|
|
#undef scanpattern2
|
|
#undef str
|
|
#undef xstr
|
|
#endif
|