class InsufficientKeySizeRsaDetector implements Detector {

    private static final String RSA_KEY_SIZE_TYPE = "RSA_KEY_SIZE";

    private BugReporter bugReporter;

    public InsufficientKeySizeRsaDetector(BugReporter bugReporter) {
        this.bugReporter = bugReporter;
    }

    @Override
    public void visitClassContext(ClassContext classContext) {
        JavaClass javaClass = classContext.getJavaClass();

        Method[] methodList = javaClass.getMethods();

        for (Method m : methodList) {
            try {
                analyzeMethod(m, classContext);
            } catch (CFGBuilderException | DataflowAnalysisException e) {
            }
        }
    }

    private void analyzeMethod(Method m, ClassContext classContext) throws CFGBuilderException, DataflowAnalysisException {<FILL_FUNCTION_BODY>}

    private void addToReport(Method m, ClassContext classContext, Location locationWeakness, Number n) {
        JavaClass clz = classContext.getJavaClass();
        int priority = (n.intValue() < 1024) ? Priorities.NORMAL_PRIORITY : Priorities.LOW_PRIORITY;
        bugReporter.reportBug(new BugInstance(this, RSA_KEY_SIZE_TYPE, priority) //
                .addClass(clz)
                .addMethod(clz, m)
                .addSourceLine(classContext, m, locationWeakness));
    }

    @Override
    public void report() {
    }
}


        //Conditions that needs to fill to identify the vulnerability
        boolean createRsaKeyGen = false;

        ConstantPoolGen cpg = classContext.getConstantPoolGen();
        CFG cfg = classContext.getCFG(m);

        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext(); ) {
            Location location = i.next();

            Instruction inst = location.getHandle().getInstruction();

            if (inst instanceof INVOKESTATIC) { //KeyPairGenerator.getInstance is called
                INVOKESTATIC invoke = (INVOKESTATIC) inst;
                if ("java.security.KeyPairGenerator".equals(invoke.getClassName(cpg)) && "getInstance".equals(invoke.getMethodName(cpg))) {
                    final List<Type> argumentTypes = Arrays.asList(invoke.getArgumentTypes(cpg));
                    String value = null;
                    if (argumentTypes.size() == 1 || argumentTypes.contains(Type.getType(Provider.class))) {
                        // getInstance(String) or getInstance(String, Provider)
                        final LDC prevInstruction = ByteCode.getPrevInstruction(location.getHandle(), LDC.class);
                        if (prevInstruction != null && prevInstruction.getType(cpg) == Type.STRING) {
                            value = (String) prevInstruction.getValue(cpg);
                        }
                    } else {
                        // getInstance(String, String)
                        value = ByteCode.getConstantLDC(location.getHandle().getPrev().getPrev(), cpg, String.class);
                    }
                    if (value != null && value.toUpperCase().startsWith("RSA")) {
                        createRsaKeyGen = true;
                    }
                }
            } else if (inst instanceof INVOKEVIRTUAL) { //KeyPairGenerator.initialize
                INVOKEVIRTUAL invoke = (INVOKEVIRTUAL) inst;
                if ("java.security.KeyPairGenerator".equals(invoke.getClassName(cpg)) && "initialize".equals(invoke.getMethodName(cpg))) {
                    Number n = null;
                    //init() with one parameter
                    if ("(I)V".equals(invoke.getSignature(cpg))) {
                        n = ByteCode.getPushNumber(location.getHandle().getPrev());
                    }
                    //init() with a second parameter an instance of SecureRandom
                    else if ("(ILjava/security/SecureRandom;)V".equals(invoke.getSignature(cpg))) {

                        SIPUSH push = ByteCode.getPrevInstruction(location.getHandle(), SIPUSH.class);
                        if (push != null) {
                            n = push.getValue();
                        }
                    }

                    if (n != null && n.intValue() < 2048 && createRsaKeyGen) {
                        addToReport(m, classContext, location, n);
                    }
                }
            } else if (inst instanceof INVOKESPECIAL) { // new RSAKeyGenParameterSpec() is called
                INVOKESPECIAL invoke = (INVOKESPECIAL) inst;
                if ("java.security.spec.RSAKeyGenParameterSpec".equals(invoke.getClassName(cpg)) && "<init>".equals(invoke.getMethodName(cpg))) {
                    Number n = null;
                    //init() with one parameter
                    if ("(ILjava/math/BigInteger;)V".equals(invoke.getSignature(cpg))) {
                        SIPUSH push = ByteCode.getPrevInstruction(location.getHandle(), SIPUSH.class);
                        if (push != null) {
                            n = push.getValue();
                        }
                    }

                    if (n != null && n.intValue() < 2048 && createRsaKeyGen) {
                        addToReport(m, classContext, location, n);
                    }
                }
            }
        }
    
<no_super_class>