clojure access enum defined inside a java class

丶灬走出姿态 提交于 2020-01-30 10:57:06

问题


I am trying to use the argon-jvm library for hashing in my application.

By default this library uses Argon2i, However, I would like to use Argon2id. To do so, I need to pass the enum value Argon2Factory.Argon2Types.Argon2id to the overloaded create method in the Argon2Factory class. Source code for Argon2Factory.java here.

From the lein repl (affter adding [de.mkammerer/argon2-jvm "2.4"] as a dependency), I can do the following:

user=> (import 'de.mkammerer.argon2.Argon2Factory)
de.mkammerer.argon2.Argon2Factory
user=> (def argon2 (Argon2Factory/create))
#'user/argon2
user=> (def hashedPassword (.hash argon2 17 65536 1 "passwordToBeHashed"))
#'user/hashedPassword
user=> hashedPassword
"$argon2i$v=19$m=65536,t=17,p=1$zvr4dz+/mpNxj5MVMtBALA$8dbE49MKV3dDfMMswTtjlB+niOeryh4EmJWNd7lj3FI"

However, I am unable to access the Argon2Types enum values (to pass to the Argon2Factory.create method) defined inside the Argon2Factory class itself. Can somone please help me access this enum?

PS: Auto-complete in the repl at different stages:

user=> (de.mkammerer.argon2.
de.mkammerer.argon2.Argon2              de.mkammerer.argon2.Argon2Advanced      de.mkammerer.argon2.Argon2Constants     de.mkammerer.argon2.Argon2Factory
de.mkammerer.argon2.Argon2Helper        de.mkammerer.argon2.Argon2d             de.mkammerer.argon2.Argon2i             de.mkammerer.argon2.Argon2id
de.mkammerer.argon2.BaseArgon2          de.mkammerer.argon2.jna.Argon2Library   de.mkammerer.argon2.jna.Argon2_type     de.mkammerer.argon2.jna.JnaUint32
de.mkammerer.argon2.jna.Size_t
user=> (de.mkammerer.argon2.Argon2Factory/create
de.mkammerer.argon2.Argon2Factory/create           de.mkammerer.argon2.Argon2Factory/createAdvanced

PPS: I will submit a pull request to this project with the Argon2Types enum defined in a .java file of its own, but in the meanntime, I would still like to know if accessing such enums is possible)


回答1:


In a REPL, try:

(import 'de.mkammerer.argon2.Argon2Factory$Argon2Types)

That works for me.



来源:https://stackoverflow.com/questions/50190749/clojure-access-enum-defined-inside-a-java-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!