Skip to content

Commit 12324fc

Browse files
committed
Factor-out implementation of svn_checksum_ctx_t into a separate file.
* subversion/libsvn_subr/checksum.c: (svn_checksum_ctx_t, svn_checksum_ctx_create, svn_checksum_ctx_reset, svn_checksum_update, svn_checksum_final): Removed. * subversion/libsvn_subr/checksum_context.c: Copied from checksum.c. (file header): Adjust file header. (includes): Cleanup includes that we no longer need. (): Remove everything from the copied file. (svn_checksum_ctx_t, svn_checksum_ctx_create, svn_checksum_ctx_reset, svn_checksum_update, svn_checksum_final): Only keeping those symbols. git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1930923 13f79535-47bb-0310-9956-ffa450edef68
1 parent 49757f2 commit 12324fc

File tree

2 files changed

+174
-136
lines changed

2 files changed

+174
-136
lines changed

subversion/libsvn_subr/checksum.c

Lines changed: 0 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -529,142 +529,6 @@ svn_checksum_empty_checksum(svn_checksum_kind_t kind,
529529
}
530530
}
531531

532-
struct svn_checksum_ctx_t
533-
{
534-
void *apr_ctx;
535-
svn_checksum_kind_t kind;
536-
};
537-
538-
svn_checksum_ctx_t *
539-
svn_checksum_ctx_create(svn_checksum_kind_t kind,
540-
apr_pool_t *pool)
541-
{
542-
svn_checksum_ctx_t *ctx = apr_palloc(pool, sizeof(*ctx));
543-
544-
ctx->kind = kind;
545-
switch (kind)
546-
{
547-
case svn_checksum_md5:
548-
ctx->apr_ctx = apr_palloc(pool, sizeof(apr_md5_ctx_t));
549-
apr_md5_init(ctx->apr_ctx);
550-
break;
551-
552-
case svn_checksum_sha1:
553-
ctx->apr_ctx = apr_palloc(pool, sizeof(apr_sha1_ctx_t));
554-
apr_sha1_init(ctx->apr_ctx);
555-
break;
556-
557-
case svn_checksum_fnv1a_32:
558-
ctx->apr_ctx = svn_fnv1a_32__context_create(pool);
559-
break;
560-
561-
case svn_checksum_fnv1a_32x4:
562-
ctx->apr_ctx = svn_fnv1a_32x4__context_create(pool);
563-
break;
564-
565-
default:
566-
SVN_ERR_MALFUNCTION_NO_RETURN();
567-
}
568-
569-
return ctx;
570-
}
571-
572-
svn_error_t *
573-
svn_checksum_ctx_reset(svn_checksum_ctx_t *ctx)
574-
{
575-
switch (ctx->kind)
576-
{
577-
case svn_checksum_md5:
578-
memset(ctx->apr_ctx, 0, sizeof(apr_md5_ctx_t));
579-
apr_md5_init(ctx->apr_ctx);
580-
break;
581-
582-
case svn_checksum_sha1:
583-
memset(ctx->apr_ctx, 0, sizeof(apr_sha1_ctx_t));
584-
apr_sha1_init(ctx->apr_ctx);
585-
break;
586-
587-
case svn_checksum_fnv1a_32:
588-
svn_fnv1a_32__context_reset(ctx->apr_ctx);
589-
break;
590-
591-
case svn_checksum_fnv1a_32x4:
592-
svn_fnv1a_32x4__context_reset(ctx->apr_ctx);
593-
break;
594-
595-
default:
596-
SVN_ERR_MALFUNCTION();
597-
}
598-
599-
return SVN_NO_ERROR;
600-
}
601-
602-
svn_error_t *
603-
svn_checksum_update(svn_checksum_ctx_t *ctx,
604-
const void *data,
605-
apr_size_t len)
606-
{
607-
switch (ctx->kind)
608-
{
609-
case svn_checksum_md5:
610-
apr_md5_update(ctx->apr_ctx, data, len);
611-
break;
612-
613-
case svn_checksum_sha1:
614-
apr_sha1_update(ctx->apr_ctx, data, (unsigned int)len);
615-
break;
616-
617-
case svn_checksum_fnv1a_32:
618-
svn_fnv1a_32__update(ctx->apr_ctx, data, len);
619-
break;
620-
621-
case svn_checksum_fnv1a_32x4:
622-
svn_fnv1a_32x4__update(ctx->apr_ctx, data, len);
623-
break;
624-
625-
default:
626-
/* We really shouldn't get here, but if we do... */
627-
return svn_error_create(SVN_ERR_BAD_CHECKSUM_KIND, NULL, NULL);
628-
}
629-
630-
return SVN_NO_ERROR;
631-
}
632-
633-
svn_error_t *
634-
svn_checksum_final(svn_checksum_t **checksum,
635-
const svn_checksum_ctx_t *ctx,
636-
apr_pool_t *pool)
637-
{
638-
*checksum = svn_checksum_create(ctx->kind, pool);
639-
640-
switch (ctx->kind)
641-
{
642-
case svn_checksum_md5:
643-
apr_md5_final((unsigned char *)(*checksum)->digest, ctx->apr_ctx);
644-
break;
645-
646-
case svn_checksum_sha1:
647-
apr_sha1_final((unsigned char *)(*checksum)->digest, ctx->apr_ctx);
648-
break;
649-
650-
case svn_checksum_fnv1a_32:
651-
*(apr_uint32_t *)(*checksum)->digest
652-
= htonl(svn_fnv1a_32__finalize(ctx->apr_ctx));
653-
break;
654-
655-
case svn_checksum_fnv1a_32x4:
656-
*(apr_uint32_t *)(*checksum)->digest
657-
= htonl(svn_fnv1a_32x4__finalize(ctx->apr_ctx));
658-
break;
659-
660-
default:
661-
/* We really shouldn't get here, but if we do... */
662-
return svn_error_create(SVN_ERR_BAD_CHECKSUM_KIND, NULL, NULL);
663-
}
664-
665-
return SVN_NO_ERROR;
666-
}
667-
668532
apr_size_t
669533
svn_checksum_size(const svn_checksum_t *checksum)
670534
{
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/*
2+
* checksum_context.c: the checksum context
3+
*
4+
* ====================================================================
5+
* Licensed to the Apache Software Foundation (ASF) under one
6+
* or more contributor license agreements. See the NOTICE file
7+
* distributed with this work for additional information
8+
* regarding copyright ownership. The ASF licenses this file
9+
* to you under the Apache License, Version 2.0 (the
10+
* "License"); you may not use this file except in compliance
11+
* with the License. You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing,
16+
* software distributed under the License is distributed on an
17+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18+
* KIND, either express or implied. See the License for the
19+
* specific language governing permissions and limitations
20+
* under the License.
21+
* ====================================================================
22+
*/
23+
24+
#define APR_WANT_BYTEFUNC
25+
26+
#include <apr_md5.h>
27+
#include <apr_sha1.h>
28+
29+
#include "svn_checksum.h"
30+
#include "svn_error.h"
31+
32+
#include "checksum.h"
33+
#include "fnv1a.h"
34+
35+
#include "svn_private_config.h"
36+
37+
38+
39+
struct svn_checksum_ctx_t
40+
{
41+
void *apr_ctx;
42+
svn_checksum_kind_t kind;
43+
};
44+
45+
svn_checksum_ctx_t *
46+
svn_checksum_ctx_create(svn_checksum_kind_t kind,
47+
apr_pool_t *pool)
48+
{
49+
svn_checksum_ctx_t *ctx = apr_palloc(pool, sizeof(*ctx));
50+
51+
ctx->kind = kind;
52+
switch (kind)
53+
{
54+
case svn_checksum_md5:
55+
ctx->apr_ctx = apr_palloc(pool, sizeof(apr_md5_ctx_t));
56+
apr_md5_init(ctx->apr_ctx);
57+
break;
58+
59+
case svn_checksum_sha1:
60+
ctx->apr_ctx = apr_palloc(pool, sizeof(apr_sha1_ctx_t));
61+
apr_sha1_init(ctx->apr_ctx);
62+
break;
63+
64+
case svn_checksum_fnv1a_32:
65+
ctx->apr_ctx = svn_fnv1a_32__context_create(pool);
66+
break;
67+
68+
case svn_checksum_fnv1a_32x4:
69+
ctx->apr_ctx = svn_fnv1a_32x4__context_create(pool);
70+
break;
71+
72+
default:
73+
SVN_ERR_MALFUNCTION_NO_RETURN();
74+
}
75+
76+
return ctx;
77+
}
78+
79+
svn_error_t *
80+
svn_checksum_ctx_reset(svn_checksum_ctx_t *ctx)
81+
{
82+
switch (ctx->kind)
83+
{
84+
case svn_checksum_md5:
85+
memset(ctx->apr_ctx, 0, sizeof(apr_md5_ctx_t));
86+
apr_md5_init(ctx->apr_ctx);
87+
break;
88+
89+
case svn_checksum_sha1:
90+
memset(ctx->apr_ctx, 0, sizeof(apr_sha1_ctx_t));
91+
apr_sha1_init(ctx->apr_ctx);
92+
break;
93+
94+
case svn_checksum_fnv1a_32:
95+
svn_fnv1a_32__context_reset(ctx->apr_ctx);
96+
break;
97+
98+
case svn_checksum_fnv1a_32x4:
99+
svn_fnv1a_32x4__context_reset(ctx->apr_ctx);
100+
break;
101+
102+
default:
103+
SVN_ERR_MALFUNCTION();
104+
}
105+
106+
return SVN_NO_ERROR;
107+
}
108+
109+
svn_error_t *
110+
svn_checksum_update(svn_checksum_ctx_t *ctx,
111+
const void *data,
112+
apr_size_t len)
113+
{
114+
switch (ctx->kind)
115+
{
116+
case svn_checksum_md5:
117+
apr_md5_update(ctx->apr_ctx, data, len);
118+
break;
119+
120+
case svn_checksum_sha1:
121+
apr_sha1_update(ctx->apr_ctx, data, (unsigned int)len);
122+
break;
123+
124+
case svn_checksum_fnv1a_32:
125+
svn_fnv1a_32__update(ctx->apr_ctx, data, len);
126+
break;
127+
128+
case svn_checksum_fnv1a_32x4:
129+
svn_fnv1a_32x4__update(ctx->apr_ctx, data, len);
130+
break;
131+
132+
default:
133+
/* We really shouldn't get here, but if we do... */
134+
return svn_error_create(SVN_ERR_BAD_CHECKSUM_KIND, NULL, NULL);
135+
}
136+
137+
return SVN_NO_ERROR;
138+
}
139+
140+
svn_error_t *
141+
svn_checksum_final(svn_checksum_t **checksum,
142+
const svn_checksum_ctx_t *ctx,
143+
apr_pool_t *pool)
144+
{
145+
*checksum = svn_checksum_create(ctx->kind, pool);
146+
147+
switch (ctx->kind)
148+
{
149+
case svn_checksum_md5:
150+
apr_md5_final((unsigned char *)(*checksum)->digest, ctx->apr_ctx);
151+
break;
152+
153+
case svn_checksum_sha1:
154+
apr_sha1_final((unsigned char *)(*checksum)->digest, ctx->apr_ctx);
155+
break;
156+
157+
case svn_checksum_fnv1a_32:
158+
*(apr_uint32_t *)(*checksum)->digest
159+
= htonl(svn_fnv1a_32__finalize(ctx->apr_ctx));
160+
break;
161+
162+
case svn_checksum_fnv1a_32x4:
163+
*(apr_uint32_t *)(*checksum)->digest
164+
= htonl(svn_fnv1a_32x4__finalize(ctx->apr_ctx));
165+
break;
166+
167+
default:
168+
/* We really shouldn't get here, but if we do... */
169+
return svn_error_create(SVN_ERR_BAD_CHECKSUM_KIND, NULL, NULL);
170+
}
171+
172+
return SVN_NO_ERROR;
173+
}
174+

0 commit comments

Comments
 (0)