forked from platypusguy/jacobin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavaSecurityEllipticCurve.go
More file actions
178 lines (161 loc) · 4.61 KB
/
javaSecurityEllipticCurve.go
File metadata and controls
178 lines (161 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
* Jacobin VM - A Java virtual machine
* Copyright (c) 2026 by the Jacobin authors. Consult jacobin.org.
* Licensed under Mozilla Public License 2.0 (MPL 2.0) All rights reserved.
*/
package javaSecurity
import (
"fmt"
"jacobin/src/excNames"
"jacobin/src/gfunction/ghelpers"
"jacobin/src/object"
"jacobin/src/types"
)
// ---------------------------------------------------------
// Loader for EllipticCurve
// ---------------------------------------------------------
func Load_EllipticCurve() {
// Constructor
ghelpers.MethodSignatures["java/security/spec/EllipticCurve.<init>(Ljava/security/spec/ECField;Ljava/math/BigInteger;Ljava/math/BigInteger;)V"] =
ghelpers.GMeth{
ParamSlots: 3,
GFunction: ellipticCurveInit,
}
// Getter for field
ghelpers.MethodSignatures["java/security/spec/EllipticCurve.getField()Ljava/security/spec/ECField;"] =
ghelpers.GMeth{
ParamSlots: 0,
GFunction: ellipticCurveGetField,
}
// Getter for a
ghelpers.MethodSignatures["java/security/spec/EllipticCurve.getA()Ljava/math/BigInteger;"] =
ghelpers.GMeth{
ParamSlots: 0,
GFunction: ellipticCurveGetA,
}
// Getter for b
ghelpers.MethodSignatures["java/security/spec/EllipticCurve.getB()Ljava/math/BigInteger;"] =
ghelpers.GMeth{
ParamSlots: 0,
GFunction: ellipticCurveGetB,
}
}
// ---------------------------------------------------------
// EllipticCurve G functions
// ---------------------------------------------------------
// Constructor: EllipticCurve(ECField field, BigInteger a, BigInteger b)
func ellipticCurveInit(params []any) any {
if len(params) != 4 { // this + field + a + b
return ghelpers.GetGErrBlk(
excNames.IllegalArgumentException,
fmt.Sprintf("ellipticCurveInit: expected 3 parameters (field, a, b), got %d", len(params)-1),
)
}
thisObj, ok := params[0].(*object.Object)
if !ok {
return ghelpers.GetGErrBlk(
excNames.IllegalArgumentException,
"ellipticCurveInit: this is not an Object",
)
}
fieldObj, ok := params[1].(*object.Object)
if !ok {
return ghelpers.GetGErrBlk(
excNames.IllegalArgumentException,
"ellipticCurveInit: param field is not an Object",
)
}
aObj, ok := params[2].(*object.Object)
if !ok {
return ghelpers.GetGErrBlk(
excNames.IllegalArgumentException,
"ellipticCurveInit: param a is not an Object",
)
}
bObj, ok := params[3].(*object.Object)
if !ok {
return ghelpers.GetGErrBlk(
excNames.IllegalArgumentException,
"ellipticCurveInit: param b is not an Object",
)
}
// Populate thisObj FieldTable
thisObj.FieldTable = map[string]object.Field{
"field": {Ftype: types.Ref, Fvalue: fieldObj},
"a": {Ftype: types.Ref, Fvalue: aObj},
"b": {Ftype: types.Ref, Fvalue: bObj},
}
return nil // <init> always returns void
}
// Getter: getField()
func ellipticCurveGetField(params []any) any {
if len(params) != 1 {
return ghelpers.GetGErrBlk(
excNames.IllegalArgumentException,
fmt.Sprintf("ellipticCurveGetField: expected 1 parameter (this), got %d", len(params)),
)
}
thisObj, ok := params[0].(*object.Object)
if !ok {
return ghelpers.GetGErrBlk(
excNames.IllegalArgumentException,
"ellipticCurveGetField: this is not an Object",
)
}
fieldObj, ok := thisObj.FieldTable["field"].Fvalue.(*object.Object)
if !ok {
return ghelpers.GetGErrBlk(
excNames.NullPointerException,
"ellipticCurveGetField: field is missing or invalid",
)
}
return fieldObj
}
// Getter: getA()
func ellipticCurveGetA(params []any) any {
if len(params) != 1 {
return ghelpers.GetGErrBlk(
excNames.IllegalArgumentException,
fmt.Sprintf("ellipticCurveGetA: expected 1 parameter (this), got %d", len(params)),
)
}
thisObj, ok := params[0].(*object.Object)
if !ok {
return ghelpers.GetGErrBlk(
excNames.IllegalArgumentException,
"ellipticCurveGetA: this is not an Object",
)
}
aObj, ok := thisObj.FieldTable["a"].Fvalue.(*object.Object)
if !ok {
return ghelpers.GetGErrBlk(
excNames.NullPointerException,
"ellipticCurveGetA: a field is missing or invalid",
)
}
return aObj
}
// Getter: getB()
func ellipticCurveGetB(params []any) any {
if len(params) != 1 {
return ghelpers.GetGErrBlk(
excNames.IllegalArgumentException,
fmt.Sprintf("ellipticCurveGetB: expected 1 parameter (this), got %d", len(params)),
)
}
thisObj, ok := params[0].(*object.Object)
if !ok {
return ghelpers.GetGErrBlk(
excNames.IllegalArgumentException,
"ellipticCurveGetB: this is not an Object",
)
}
bObj, ok := thisObj.FieldTable["b"].Fvalue.(*object.Object)
if !ok {
return ghelpers.GetGErrBlk(
excNames.NullPointerException,
"ellipticCurveGetB: b field is missing or invalid",
)
}
return bObj
}