Add some time-related helpers
[openafs.git] / src / rxgk / rxgk.h
1 /* rxgk.h - External interfaces for RXGK */
2 /*
3  * Copyright (C) 2013, 2014 by the Massachusetts Institute of Technology.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  *   notice, this list of conditions and the following disclaimer.
12  *
13  * * Redistributions in binary form must reproduce the above copyright
14  *   notice, this list of conditions and the following disclaimer in
15  *   the documentation and/or other materials provided with the
16  *   distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29  * OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31
32 /*
33  * External interfaces for RXGK.
34  */
35
36 #ifndef OPENAFS_RXGK_H
37 #define OPENAFS_RXGK_H
38
39 /* Pull in the com_err table */
40 #include <rx/rxgk_errs.h>
41
42 /* Pull in the protocol description */
43 #include <rx/rxgk_int.h>
44
45 /* rxgkTime is defined in rxgk_int.xg. rxgkTime values are unix timestamps, but
46  * in 100-nanosecond units. */
47
48 /* Helpers to avoid having to count zeros. */
49 static_inline rxgkTime secondsToRxgkTime(afs_uint64 seconds) {
50     return seconds * (rxgkTime)10000000;
51 }
52 static_inline afs_uint64 rxgkTimeToSeconds(rxgkTime atime) {
53     return (afs_uint64)atime / 10000000;
54 }
55
56 /** Get the current timestamp as an rxgkTime. */
57 static_inline rxgkTime RXGK_NOW(void)
58 {
59     struct timeval tv;
60     osi_GetTime(&tv);
61     return secondsToRxgkTime(tv.tv_sec) + (rxgkTime)tv.tv_usec * 10;
62 }
63
64 /* rxgk_key is an opaque type to wrap our RFC3961 implementation's concept
65  * of a key.  It has (at least) the keyblock and length, and enctype. */
66 typedef void * rxgk_key;
67
68 typedef afs_int32 (*rxgk_getkey_func)(void *rock, afs_int32 *kvno,
69                                       afs_int32 *enctype, rxgk_key *key);
70 /* rxgk_server.c */
71 struct rx_securityClass * rxgk_NewServerSecurityObject(void *getkey_rock,
72                                                        rxgk_getkey_func getkey);
73 /* rxgk_client.c */
74 struct rx_securityClass *rxgk_NewClientSecurityObject(RXGK_Level level,
75                                                       afs_int32 enctype,
76                                                       rxgk_key k0,
77                                                       RXGK_Data *token,
78                                                       afsUUID *uuid);
79
80 #endif /* OPENAFS_RXGK_H */